test(compiler): cover namespace trailing comment variants

pull/29/head
韩天峰 1 month ago
parent a3d8f57ef4
commit eadac69dcd
  1. 14
      phpunit/code/preprocessor/namespace_ending_comment_unbracketed.php
  2. 19
      phpunit/src/PreprocessorTest.php
  3. 4
      tests/compiler/namespace/namespace-ending-comment.phpt

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace NamespaceEndingComment;
const VALUE = 42;
function value(): int
{
return VALUE;
}
// unbracketed namespace trailing comment

@ -321,6 +321,25 @@ class PreprocessorTest extends TestCase
$this->assertSame('App\\VERSION', $constants['_const_var_App__VERSION']->name); $this->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 public function testSortFilesUsesImplementsAndTraitDependencies(): void
{ {
$classFile = realpath(__DIR__ . '/../code/preprocessor/deps_class_implements.php'); $classFile = realpath(__DIR__ . '/../code/preprocessor/deps_class_implements.php');

@ -6,7 +6,7 @@ A namespace block ending with a comment must not be treated as stray code
declare(strict_types=1); declare(strict_types=1);
namespace Test { namespace Test {
// test /* named namespace trailing block comment */
} }
namespace { namespace {
@ -15,7 +15,7 @@ namespace {
var_dump('done'); var_dump('done');
} }
// test1 // global namespace trailing line comment
} }
?> ?>
--EXPECT-- --EXPECT--

Loading…
Cancel
Save