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 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')); 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]);