Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Testing/PHPUnit/AbstractRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/NodeManipulator/ClassDependencyManipulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'));
Expand Down
19 changes: 19 additions & 0 deletions tests/Testing/ResetSourceLocator/Fixture/some_function.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Rector\Tests\Testing\ResetSourceLocator\Fixture;

function some_function()
{
}

?>
-----
<?php

namespace Rector\Tests\Testing\ResetSourceLocator\Fixture;

function some_function(): void
{
}

?>
30 changes: 30 additions & 0 deletions tests/Testing/ResetSourceLocator/ResetSourceLocatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Testing\ResetSourceLocator;

use PHPUnit\Framework\Attributes\Depends;
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class ResetSourceLocatorTest extends AbstractRectorTestCase
{
public function testProcessFixture(): void
{
$this->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';
}
}
9 changes: 9 additions & 0 deletions tests/Testing/ResetSourceLocator/config/configured_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\Function_\AddFunctionVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
->withRules([AddFunctionVoidReturnTypeWhereNoReturnRector::class]);
Loading