spaze / phpstan-disallowed-calls

PHPStan rules to detect disallowed method & function calls, constant, namespace, attribute & superglobal usages
MIT License
255 stars 17 forks source link

Wrong file order in tests/bootstrap.php #211

Closed enumag closed 1 year ago

enumag commented 1 year ago

Hi I'm experimenting with this package locally and ran into a problem:

> vendor/bin/phpunit --colors=always
PHP Fatal error:  Trait "Traits\TestTrait" not found in /home/enumag/Projects/spaze/phpstan-disallowed-calls/tests/libs/Traits.php on line 27
PHP Stack trace:
PHP   1. {main}() /home/enumag/Projects/spaze/phpstan-disallowed-calls/vendor/bin/phpunit:0
PHP   2. include() /home/enumag/Projects/spaze/phpstan-disallowed-calls/vendor/bin/phpunit:123
PHP   3. PHPUnit\TextUI\Application->run($argv = [0 => 'vendor/bin/phpunit', 1 => '--colors=always']) /home/enumag/Projects/spaze/phpstan-disallowed-calls/vendor/phpunit/phpunit/phpunit:99
PHP   4. PHPUnit\TextUI\Application->loadBootstrapScript($filename = '/home/enumag/Projects/spaze/phpstan-disallowed-calls/tests/bootstrap.php') /home/enumag/Projects/spaze/phpstan-disallowed-calls/vendor/phpunit/phpunit/src/TextUI/Application.php:97
PHP   5. include_once() /home/enumag/Projects/spaze/phpstan-disallowed-calls/vendor/phpunit/phpunit/src/TextUI/Application.php:291
PHP   6. require_once() /home/enumag/Projects/spaze/phpstan-disallowed-calls/tests/bootstrap.php:9
Script vendor/bin/phpunit --colors=always handling the phpunit event returned with error code 255

The cause of this is that RecursiveDirectoryIterator doesn't return the filed ordered alphabetically on linux so it tried to load Traits.php before TestTrait.php.

spaze commented 1 year ago

Hmm, interesting :-) I've added the autoloading using the iterator in #204 and it works on my Linux (WSL2) and also in CI. But I guess the order the items are returned in is some kind of "disk order" which generally could be random. Sorting wouldn't in cases like class B extends A so I'll probably revert to manual bootstrap.php updates.

spaze commented 1 year ago

The fix for this has now been released in 2.16.0. I've reverted to listing the required files manually and created a test to test that they're all there :-) I like this even better than the autoloading.