diff --git a/scoper.php b/scoper.php index d6da45ea9e7..2dcf08eb98f 100644 --- a/scoper.php +++ b/scoper.php @@ -119,7 +119,7 @@ static function (string $filePath, string $prefix, string $content): string { return Strings::replace( $content, - '#(public function getRuleDefinition\(\): RuleDefinition\s+\{\R)(.*?)(\R \})#s', + '#(public function getRuleDefinition\(\): RuleDefinition\s+\{\R)(.*?)(\R\s*\);\R\s*\})#s', static function (array $match) use ($prefix): string { $body = str_replace($prefix . '\\', '', $match[2]); $body = Strings::replace($body, '#^\s*namespace ' . preg_quote($prefix, '#') . ';\R\R?#m', ''); diff --git a/tests/Scoper/ScoperPatchersTest.php b/tests/Scoper/ScoperPatchersTest.php index 860db4d4a63..4fb1331a175 100644 --- a/tests/Scoper/ScoperPatchersTest.php +++ b/tests/Scoper/ScoperPatchersTest.php @@ -4,7 +4,6 @@ namespace Rector\Tests\Scoper; -use Webmozart\Assert\Assert; use Closure; use PHPUnit\Framework\TestCase; use Symfony\Component\Finder\Finder; @@ -30,28 +29,39 @@ public function getRuleDefinition(): RuleDefinition { $metadata = 'RectorPrefix202607\Webmozart\Assert\Assert'; - new ConfiguredCodeSample( - <<<'CODE_SAMPLE' + return new RuleDefinition( + 'Demo', + [ + new ConfiguredCodeSample( + <<<'CODE_SAMPLE' assertStringContainsString('use Webmozart\Assert\Assert;', (string) $content); $this->assertStringContainsString('use RectorPrefix202607\Webmozart\Assert\Assert;', (string) $content); - $this->assertStringContainsString(Assert::class . '::allString($items);', (string) $content); + $this->assertStringContainsString('\Webmozart\Assert\Assert::allString($items);', (string) $content); $this->assertStringContainsString("'SomeVendor\ValueObject::class'", (string) $content); $this->assertStringContainsString("'new SomeVendor\ValueObject()'", (string) $content); $this->assertStringContainsString('$metadata = \'Webmozart\Assert\Assert\';', (string) $content);