-
-
Notifications
You must be signed in to change notification settings - Fork 416
[autoload] Add workaround for phpstan + rector tests co-run to avoid duplicated php-parser loading error #7440
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
24393b4 to
a264677
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may cause invalid phpunit test for rector rules, since we need load preload script, see
rector-src/src/Testing/PHPUnit/AbstractLazyTestCase.php
Lines 62 to 75 in 366f329
| private function includePreloadFilesAndScoperAutoload(): void | |
| { | |
| if (file_exists(__DIR__ . '/../../../preload.php')) { | |
| if (file_exists(__DIR__ . '/../../../vendor')) { | |
| require_once __DIR__ . '/../../../preload.php'; | |
| // test case in rector split package | |
| } elseif (file_exists(__DIR__ . '/../../../../../../vendor')) { | |
| require_once __DIR__ . '/../../../preload-split-package.php'; | |
| } | |
| } | |
| if (\file_exists(__DIR__ . '/../../../vendor/scoper-autoload.php')) { | |
| require_once __DIR__ . '/../../../vendor/scoper-autoload.php'; | |
| } |
Also, please run the script:
php build/build-preload.php .
so it regenerated and we can test.
a56cb3d to
9ff48de
Compare
…duplicated php-parser loading error
9ff48de to
d1f3cf3
Compare
| use PhpParser\Node; | ||
| use PHPStan\Testing\PHPStanTestCase; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may cause repetitive apply cs after rebuild weekly, if cs is required, the cs fix position needs to be after generate preload on workflow build so it always have same result:
rector-src/.github/workflows/weekly_pull_requests.yaml
Lines 21 to 29 in 89bfc23
| - | |
| name: 'Apply Coding Standard' | |
| run: "composer fix-cs" | |
| branch: 'automated-apply-coding-standards' | |
| - | |
| name: 'Re-Generate preload.php' | |
| run: "composer preload" | |
| branch: 'automated-regenerated-preload' |
or on build/build-preload.php script, or add use statement early there.
|
/cc @Androoha1 @nikophil @staabm @megawubs could you verify manual this patch, thank you. update |
|
Also @ostrolucky @smnandre could you verify manual this patch with the following steps, thank you.
Ref of existing PR on your repository that use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomasVotruba I tested manually on https://github.com/ostrolucky/rector-rules repository, and seems still error:
➜ rector-rules git:(main) ✗ vendor/bin/phpunit
PHP Fatal error: Cannot declare interface PhpParser\NodeVisitor, because the name is already in use in /Users/samsonasik/www/rector-rules/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor.php on line 6
Fatal error: Cannot declare interface PhpParser\NodeVisitor, because the name is already in use in /Users/samsonasik/www/rector-rules/vendor/rector/rector/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor.php on line 6
Step to reproduce:
- git clone https://github.com/ostrolucky/rector-rules
- Run composer install
- Manually update
vendor/rector/rector/preload.phpwith the patch. - Run
vendor/bin/phpunit
@samsonasik what do you want to be tested? |
|
@staabm I already tested on phpunit 12, and it still error with this patch as above #7440 (review) Step to reproduce:
|
|
@samsonasik This is not related to PHPUnit 12. This bug existed before. It's about order of the tests loaded. |
|
@TomasVotruba then the tweak still needed? I tested on https://github.com/ostrolucky/rector-rules, apply this patch, and still error. |
|
Let's give it a go. Test this in projects with both PHPStan and Rector tests. |
|
@samsonasik For PHPUnit 12, yes. This is not related to PHPUnit version, but autoload. |
| '*/Expected/*', | ||
|
|
||
| // avoid re-running on build | ||
| __DIR__ . '/preload.php', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also preload-split-package.php:
| __DIR__ . '/preload.php', | |
| __DIR__ . '/preload.php', | |
| __DIR__ . '/preload-split-package.php', |
|
I'll check https://github.com/ostrolucky/rector-rules repo |
| } | ||
|
|
||
| return interface_exists(Node::class, false); | ||
| }require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new line is needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Let's try reviving 3 years old PR that solves this magic autoload workarounds :) |
|
@TomasVotruba for note, we not only patch to apply so we still can't rely on "in project" nikic/php-parser vendor. |
|
@TomasVotruba in rector-src/build/build-preload.php Lines 172 to 186 in 69ccff5
|
|
@samsonasik Let's resolve one problem at a time. |
|
Hi @samsonasik sorry for the late reply. I tried to update rector, and manualy modify tried on Foundry's rules : |
|
@nikophil This is not related to your issue. It's a different case: #7440 (comment) |
This happens when: