-
-
Notifications
You must be signed in to change notification settings - Fork 430
[Alternative] Let preload.php require on PHPUnit < 12 on AbstractLazyTestCase #7452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@nikophil I tested on your repo with steps:
git clone git@github.com:zenstruck/foundry.git
cd foundry
composer install
composer bin rector install
composer bin phpstan install
-require \dirname(__DIR__).'/../../bin/tools/rector/vendor/rector/rector/preload.php';
➜ foundry git:(2.x) php84 vendor/bin/phpunit -c phpunit-rector.xml.dist
PHPUnit 12.4.0 by Sebastian Bergmann and contributors.
Runtime: PHP 8.4.0RC1
Configuration: /Users/samsonasik/www/foundry/phpunit-rector.xml.dist
....................................... 39 / 39 (100%)
Time: 00:00.367, Memory: 76.50 MB
OK (39 tests, 49 assertions)which seems working ok 👍 |
|
@ostrolucky I tested on your repo with the following steps:
git clone https://github.com/ostrolucky/rector-rules
cd rector-rules
composer install
-require dirname(__DIR__) . '/vendor/rector/rector/preload.php';
vendor/bin/phpunit
PHPUnit 12.4.0 by Sebastian Bergmann and contributors.
Runtime: PHP 8.3.12
Configuration: /Users/samsonasik/www/rector-rules/phpunit.xml.dist
WARNING: On fixture file "array_access_fixture.php.inc" for test "Ostrolucky\Test\RectorRules\Rector\RemoveUnnecessaryEmptyRector\RemoveUnnecessaryEmptyRectorTest"
File not changed but some Rector rules applied:
* Ostrolucky\RectorRules\RemoveUnnecessaryEmptyRector
.....
WARNING: On fixture file "superglobal_variable_fixture.php.inc" for test "Ostrolucky\Test\RectorRules\Rector\RemoveUnnecessaryEmptyRector\RemoveUnnecessaryEmptyRectorTest"
File not changed but some Rector rules applied:
* Ostrolucky\RectorRules\RemoveUnnecessaryEmptyRector
. 6 / 6 (100%)
Time: 00:00.273, Memory: 80.50 MB
OK (6 tests, 7 assertions)which seems working ok 👍 (warning notice is unrelated, due to not return null on no change on the custom rules) |
|
/cc @Androoha1 @staabm @megawubs @ivastly @nikophil @devnix @smnandre I need help to test this PR patch:
bootstrap="./tests/bootstrap.php"in phpunit.xml, then in -require dirname(__DIR__) . '/vendor/rector/rector/preload.php';
|
|
@TomasVotruba I manually test this patch PR https://github.com/rectorphp/rector-src/pull/7452/files#diff-cb464ba580e5b47644d6f1062f03d797d3bfc6d7e540e5efded419ceb004e5b0 on https://github.com/laminas/laminas-servicemanager-migration repo with requirre PHPUnit 12+ and it seems working OK, the node check with var_dump($node instanceof StmtsAwareInterface);and run phpunit show vendor/bin/phpunit test/Rector/Class_/ImplementsFactoryInterfaceToPsrFactoryRector/AutoImportRenameUseTest.php
PHPUnit 12.4.0 by Sebastian Bergmann and contributors.
Runtime: PHP 8.3.12
Configuration: /Users/samsonasik/www/laminas-servicemanager-migration/phpunit.xml.dist
bool(true)which seems working OK as our own node type detected as "true" 👍 |
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
|
@samsonasik this is awesome, thank you for your work! |
|
@TomasVotruba this can possibly better solution :), this only modify the Tested in community rules and seems more our php-parser vendor already loaded early, see above tests. |
|
I prefer the other one, because it's single place used for all race-condition preloads 👍 If something loads PHPUnit and then Rector test case, we have the same bug. This would happen e.g. while PHPStan test case is run → PHPUnit is loaded → then php-parser of PHPUnit is loaded and crash. |
|
@TomasVotruba that seems issue on custom vendor directory for rector, so autolad loaded later, see On foundry repo usecase, the rector vendor is on different location vs project vendor, while later I recommend to use dedicated single location for rector vendor and project vendor, but still |
|
@nikophil since the approved solution is the patch on rector bootstrap The only way to work on your use case on your foundry repo is by use |
@TomasVotruba per #7451 (comment)
This is alternative that it only load
preload.phpwhen on phpunit < 12. As PHPUnit 12+ load vendor/autoload.php too early.I will need help on verify on community rules to test the manual patch :)