From 5281ad761ad532abebae35c0e6646ad457a2bcdb Mon Sep 17 00:00:00 2001 From: Guillaume Erpeldinger Date: Wed, 23 Sep 2026 16:03:20 +0200 Subject: [PATCH 1/3] [Testing] Add test for source locator after a Rector test --- .../Fixture/some_function.php.inc | 19 ++++++++++++ .../ResetSourceLocatorTest.php | 30 +++++++++++++++++++ .../config/configured_rule.php | 9 ++++++ 3 files changed, 58 insertions(+) create mode 100644 tests/Testing/ResetSourceLocator/Fixture/some_function.php.inc create mode 100644 tests/Testing/ResetSourceLocator/ResetSourceLocatorTest.php create mode 100644 tests/Testing/ResetSourceLocator/config/configured_rule.php diff --git a/tests/Testing/ResetSourceLocator/Fixture/some_function.php.inc b/tests/Testing/ResetSourceLocator/Fixture/some_function.php.inc new file mode 100644 index 00000000000..e96e0cfcc9a --- /dev/null +++ b/tests/Testing/ResetSourceLocator/Fixture/some_function.php.inc @@ -0,0 +1,19 @@ + +----- + diff --git a/tests/Testing/ResetSourceLocator/ResetSourceLocatorTest.php b/tests/Testing/ResetSourceLocator/ResetSourceLocatorTest.php new file mode 100644 index 00000000000..d7fd31e0640 --- /dev/null +++ b/tests/Testing/ResetSourceLocator/ResetSourceLocatorTest.php @@ -0,0 +1,30 @@ +doTestFile(__DIR__ . '/Fixture/some_function.php.inc'); + } + + #[Depends('testProcessFixture')] + public function testNextTestDoesNotLocateDeletedInputFile(): void + { + $dynamicSourceLocatorProvider = $this->make(DynamicSourceLocatorProvider::class); + + $this->assertTrue($dynamicSourceLocatorProvider->arePathsEmpty()); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Testing/ResetSourceLocator/config/configured_rule.php b/tests/Testing/ResetSourceLocator/config/configured_rule.php new file mode 100644 index 00000000000..f76ef31b1e3 --- /dev/null +++ b/tests/Testing/ResetSourceLocator/config/configured_rule.php @@ -0,0 +1,9 @@ +withRules([AddFunctionVoidReturnTypeWhereNoReturnRector::class]); From e8c3b425b643e7daae944c9528acc79b9b27b113 Mon Sep 17 00:00:00 2001 From: Guillaume Erpeldinger Date: Wed, 23 Sep 2026 16:04:17 +0200 Subject: [PATCH 2/3] [Testing] Reset source locator after each Rector test --- src/Testing/PHPUnit/AbstractRectorTestCase.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Testing/PHPUnit/AbstractRectorTestCase.php b/src/Testing/PHPUnit/AbstractRectorTestCase.php index f90461c745a..65917eb0415 100644 --- a/src/Testing/PHPUnit/AbstractRectorTestCase.php +++ b/src/Testing/PHPUnit/AbstractRectorTestCase.php @@ -134,6 +134,9 @@ protected function tearDown(): void if (is_string($this->inputFilePath)) { FileSystem::delete($this->inputFilePath); } + + // a next test that does not set its own paths would still locate the deleted file + $this->dynamicSourceLocatorProvider->reset(); } protected static function yieldFilesFromDirectory(string $directory, string $suffix = '*.php.inc'): Iterator From c315ceb371fd159fcfb7778d051d0a9dc03e4f35 Mon Sep 17 00:00:00 2001 From: Guillaume Erpeldinger Date: Wed, 23 Sep 2026 01:41:58 +0200 Subject: [PATCH 3/3] [Testing] Reset PHP version after ClassDependencyManipulatorTest --- tests/NodeManipulator/ClassDependencyManipulatorTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/NodeManipulator/ClassDependencyManipulatorTest.php b/tests/NodeManipulator/ClassDependencyManipulatorTest.php index 2d1a89942dc..282ebb31dc4 100644 --- a/tests/NodeManipulator/ClassDependencyManipulatorTest.php +++ b/tests/NodeManipulator/ClassDependencyManipulatorTest.php @@ -22,6 +22,7 @@ use Rector\NodeManipulator\ClassDependencyManipulator; use Rector\PostRector\ValueObject\PropertyMetadata; use Rector\Testing\PHPUnit\AbstractLazyTestCase; +use Rector\ValueObject\PhpVersion; use Rector\ValueObject\PhpVersionFeature; final class ClassDependencyManipulatorTest extends AbstractLazyTestCase @@ -42,6 +43,12 @@ protected function setUp(): void SimpleParameterProvider::setParameter(Option::PHP_VERSION_FEATURES, PhpVersionFeature::READONLY_PROPERTY); } + protected function tearDown(): void + { + // reset to the test default, so the next test class in the same process does not run on PHP 8.1 + SimpleParameterProvider::setParameter(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_10); + } + public function testEmptyClass(): void { $someClass = new Class_(new Identifier('EmptyClass'));