Skip to content

[Testing] Reset source locator after each Rector test - #8513

Merged
TomasVotruba merged 3 commits into
rectorphp:mainfrom
GErpeldinger:reset-source-locator-after-test
Sep 23, 2026
Merged

TomasVotruba merged 3 commits into
rectorphp:mainfrom
GErpeldinger:reset-source-locator-after-test

Conversation

@GErpeldinger

@GErpeldinger GErpeldinger commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

DynamicSourceLocatorProvider keeps the temporary file of the last doTestFile(). tearDown() deletes that file, so the next test class in the same process that sets no paths itself, e.g. MultilineTest or PhpDocInfoPrinterTest, looks up names in a deleted file:

hash_file(.../AddFunctionVoidReturnTypeWhereNoReturnRector/Fixture/some_function.php): Failed to open stream: No such file or directory

This warning is in 42 of the 70 failed test runs since 2026-08-14 (see #8512 (comment)). It never fails a run, but it is noise next to the real failure. tearDown() now resets the provider. The first commit only adds ResetSourceLocatorTest, and CI fails on it.

Third commit: ClassDependencyManipulatorTest sets the PHP version to 8.1 and never resets it. When it runs before AddOverrideAttributeToOverriddenPropertiesRectorTest in the same process, the parent property gets no #[\Override], because the rule needs PHP 8.5. This is the order-dependent failure of #8464 and #8465: the cause is this parameter, not reflection. main at 1d0224b already failed this way with 3 workers, and the new test class of this PR makes it fail with 4: see the CI run of the first commit.

#8349 resets the PHP version in AbstractRectorTestCase::tearDownAfterClass(), but ClassDependencyManipulatorTest extends AbstractLazyTestCase, so it now resets it in its own tearDown(). To reproduce:

vendor/bin/phpunit tests/NodeManipulator/ClassDependencyManipulatorTest.php rules-tests/Php85/Rector/Property/AddOverrideAttributeToOverriddenPropertiesRector/AddOverrideAttributeToOverriddenPropertiesRectorTest.php

With both fixes, the full suite passes with no Failed to open stream warning for every worker count from 2 to 12. On main at 1d0224b, 7 of these 11 runs have the warning, and the 3-worker run fails.

🤖 Drafted with AI assistance.

@TomasVotruba

Copy link
Copy Markdown
Member

Thanks for the PR.
Can you add one commit that shows CI failing without this fix?

@GErpeldinger
GErpeldinger force-pushed the reset-source-locator-after-test branch from 08ed128 to 5281ad7 Compare September 23, 2026 14:04
@GErpeldinger

Copy link
Copy Markdown
Contributor Author

Done: the first commit only adds the test, and CI fails on it on PHP 8.4 and 8.5 (https://github.com/rectorphp/rector-src/actions/runs/35871477885): ResetSourceLocatorTest and AddOverrideAttributeToOverriddenPropertiesRectorTest. The next two commits are the fixes.

The AddOverrideAttributeToOverriddenPropertiesRectorTest failure is the one from #8464 and #8465: ClassDependencyManipulatorTest leaves the PHP version at 8.1, the "parameters order" of #8471. I updated the description with the details.

🤖 Drafted with AI assistance.

@TomasVotruba
TomasVotruba merged commit 3e70199 into rectorphp:main Sep 23, 2026
45 checks passed
@TomasVotruba

Copy link
Copy Markdown
Member

LGTM, lets give this a go. Thanks

@TomasVotruba

Copy link
Copy Markdown
Member

I ran perf test locally and there is no difference in performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants