pest icon indicating copy to clipboard operation
pest copied to clipboard

[Bug]: Architecture test expectations don't seem to respect phpunit.xml directory exclude

Open antero111 opened this issue 4 months ago • 0 comments

What Happened

I have database seeders that are fairly large with about 800k lines of code under Laravels database folder.

Seeders have been generated with https://github.com/orangehill/iseed. Seeder file format is described here. Bulk of the lines is long arrays of DB inserts.

I am running vendor/bin/pest --testsuite Architecture where my architecture suite runs the Laravel preset with arch()->preset()->laravel();

Tests run and complete Ok but duration is nearly 80 seconds.

To fix this I have defined directory exclude for my test suite in my phpunit.xml since I expect the not->toBeUsed assertions taking long time to process the files.

phpunit.xml:

     <source>
        <include>
            <directory suffix=".php">app</directory>
        </include>
        <exclude>
            <directory>database</directory>
        </exclude>
    </source>

One of the expectations from preset source:

       expect([
            'dd',
            'ddd',
            'dump',
            'env',
            'exit',
            'ray',
        ])->not->toBeUsed();

After debugging the issue for a (long) while, I found out that if I try to remove my database folder and then run the tests again, the same arch test completes in acceptable 6 seconds or so.

Also I found out that if I place e.g. a single dd call to some file under the database folder (e.g. "database/factories/SomeModelFactory.php"), it causes the preset test to fail which I fully expect not to since I have excluded the folder from test analysis.

Additionally the tested code ammount and related test duration is closely linked so that if lines of code is doubled, the durations doubles also. (Goes little out of topic but is there any performance improvements to be achieved with some code refactoring? My projects tested lines of code is only little over 20k and it already takes 6-7 seconds to assert those. What about projects with 10x that ammount?)

Any ideas how to debug this further?

Thanks in advance.

How to Reproduce

Fresh Laravel Sail app with Architecture testing configured with Laravel (or any other not->toBeUsed() assertion e.g. arch()->expect(['dd'])->not->toBeUsed();) and very large php source files in exluded folders.

Then run tests and expect it to take long time.

Sample Repository

No response

Pest Version

4.1.2

PHP Version

8.4.8

Operation System

Linux

Notes

Versions:

pestphp/pest                                   4.1.2   The elegant PHP Testing Framework.
pestphp/pest-plugin                            4.0.0   The Pest plugin manager
pestphp/pest-plugin-arch                       4.0.0   The Arch plugin for Pest PHP.
pestphp/pest-plugin-laravel                    4.0.0   The Pest Laravel Plugin
pestphp/pest-plugin-mutate                     4.0.1   Mutates your code to find untested cases
pestphp/pest-plugin-profanity                  4.1.0   The Pest Profanity Plugin

OS: Win11 with WSL2 Docker Sail container.

antero111 avatar Oct 24 '25 20:10 antero111