diff --git a/src/Prefixer.php b/src/Prefixer.php index 06877b24..90c6007e 100644 --- a/src/Prefixer.php +++ b/src/Prefixer.php @@ -217,7 +217,7 @@ public function replaceClassname($contents, $originalClassname, $classnamePrefix # the remainder of the string. namespace\s+[a-zA-Z0-9_\x7f-\xff\\\\]+; # Skip lines just declaring the namespace. | - ([^a-zA-Z0-9_\x7f-\xff\$])('. $searchClassname . ')([^a-zA-Z0-9_\x7f-\xff]) + ([^a-zA-Z0-9_\x7f-\xff\$\\\])('. $searchClassname . ')([^a-zA-Z0-9_\x7f-\xff\\\]) /x'; // # x: ignore whitespace in regex. diff --git a/tests/Unit/PrefixerTest.php b/tests/Unit/PrefixerTest.php index 9d183d63..22a9b6d8 100644 --- a/tests/Unit/PrefixerTest.php +++ b/tests/Unit/PrefixerTest.php @@ -1317,4 +1317,74 @@ class NA $this->assertEquals($contents, $result); } + + /** + * class Normalizer_Test_Normalizer extends Normalizer_Test\Symfony\Polyfill\Intl\Normalizer_Test_Normalizer\Normalizer + * + * @throws \Exception + */ + public function testItDoesNotPrefixClassnameInsideInsideNamespaceName(): void + { + + $contents = <<<'EOD' +class Normalizer extends Symfony\Polyfill\Intl\Normalizer\Foo +{ + +} +EOD; + + $expected = <<<'EOD' +class Normalizer_Test_Normalizer extends Symfony\Polyfill\Intl\Normalizer\Foo +{ + +} +EOD; + + $originalClassname = 'Normalizer'; + $classnamePrefix = 'Normalizer_Test_'; + + $config = $this->createMock(StraussConfig::class); + + $replacer = new Prefixer($config, __DIR__); + + $result = $replacer->replaceClassname($contents, $originalClassname, $classnamePrefix); + + $this->assertEquals($expected, $result); + } + + + + /** + * class Normalizer_Test_Normalizer extends Normalizer_Test\Symfony\Polyfill\Intl\Normalizer_Test_Normalizer\Normalizer + * + * @throws \Exception + */ + public function testItDoesNotPrefixClassnameInsideEndNamespaceName(): void + { + + $contents = <<<'EOD' +class Normalizer extends Symfony\Polyfill\Intl\Foo\Normalizer +{ + +} +EOD; + + $expected = <<<'EOD' +class Normalizer_Test_Normalizer extends Symfony\Polyfill\Intl\Foo\Normalizer +{ + +} +EOD; + + $originalClassname = 'Normalizer'; + $classnamePrefix = 'Normalizer_Test_'; + + $config = $this->createMock(StraussConfig::class); + + $replacer = new Prefixer($config, __DIR__); + + $result = $replacer->replaceClassname($contents, $originalClassname, $classnamePrefix); + + $this->assertEquals($expected, $result); + } }