diff --git a/phpunit/code/preprocessor/namespace_ending_comment_unbracketed.php b/phpunit/code/preprocessor/namespace_ending_comment_unbracketed.php new file mode 100644 index 00000000..7ad8b333 --- /dev/null +++ b/phpunit/code/preprocessor/namespace_ending_comment_unbracketed.php @@ -0,0 +1,14 @@ +assertSame('App\\VERSION', $constants['_const_var_App__VERSION']->name); } + public function testNamespaceEndingCommentWithUnbracketedSyntaxIsIgnored(): void + { + global $translator; + $file = __DIR__ . '/../code/preprocessor/namespace_ending_comment_unbracketed.php'; + $previousTranslator = $translator ?? null; + $translator = $this->compiler; + + try { + $this->compiler->addFiles([$file]); + $this->compiler->prepareFile($file); + $this->compiler->convertFile($file); + } finally { + $translator = $previousTranslator; + } + + $constants = $this->getProperty('constants'); + $this->assertArrayHasKey('_const_var_NamespaceEndingComment__VALUE', $constants); + } + public function testSortFilesUsesImplementsAndTraitDependencies(): void { $classFile = realpath(__DIR__ . '/../code/preprocessor/deps_class_implements.php'); diff --git a/tests/compiler/namespace/namespace-ending-comment.phpt b/tests/compiler/namespace/namespace-ending-comment.phpt index fa0f3da0..e937a711 100644 --- a/tests/compiler/namespace/namespace-ending-comment.phpt +++ b/tests/compiler/namespace/namespace-ending-comment.phpt @@ -6,7 +6,7 @@ A namespace block ending with a comment must not be treated as stray code declare(strict_types=1); namespace Test { - // test + /* named namespace trailing block comment */ } namespace { @@ -15,7 +15,7 @@ namespace { var_dump('done'); } - // test1 + // global namespace trailing line comment } ?> --EXPECT--