From 3a90651a0f38620a7ba6c4433472fd7cb85adc9c Mon Sep 17 00:00:00 2001 From: Mykola Martynov Date: Fri, 11 Aug 2023 17:21:17 +0300 Subject: [PATCH 1/3] add test case with closure and use statement --- tests/unit/Types/ContextFactoryTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/unit/Types/ContextFactoryTest.php b/tests/unit/Types/ContextFactoryTest.php index 28a3d5d..8aead97 100644 --- a/tests/unit/Types/ContextFactoryTest.php +++ b/tests/unit/Types/ContextFactoryTest.php @@ -139,6 +139,31 @@ public function bar() $this->assertSame([], $context->getNamespaceAliases()); } + public function testTraitContainsClosureWithUseStatement() : void + { + $php = 'createForNamespace('Foo', $php); + + $this->assertSame([], $context->getNamespaceAliases()); + } + /** * @covers ::createFromReflector */ From b430dd90bf56ba4c7b999d05ad3e0a76594d3d30 Mon Sep 17 00:00:00 2001 From: Mykola Martynov Date: Fri, 11 Aug 2023 17:21:46 +0300 Subject: [PATCH 2/3] update ContextFactory::createForNamespace --- src/Types/ContextFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Types/ContextFactory.php b/src/Types/ContextFactory.php index 892ee0f..4909ab7 100644 --- a/src/Types/ContextFactory.php +++ b/src/Types/ContextFactory.php @@ -181,6 +181,7 @@ public function createForNamespace(string $namespace, string $fileContents): Con $currentNamespace = $this->parseNamespace($tokens); break; case T_CLASS: + case T_TRAIT: // Fast-forward the iterator through the class so that any // T_USE tokens found within are skipped - these are not // valid namespace use statements so should be ignored. From 4ec06f8cf4a14db2fa4fc4fd255a30096e06f2bd Mon Sep 17 00:00:00 2001 From: Mykola Martynov Date: Fri, 11 Aug 2023 17:35:41 +0300 Subject: [PATCH 3/3] add covers phpdoc --- tests/unit/Types/ContextFactoryTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit/Types/ContextFactoryTest.php b/tests/unit/Types/ContextFactoryTest.php index 8aead97..9aa97ae 100644 --- a/tests/unit/Types/ContextFactoryTest.php +++ b/tests/unit/Types/ContextFactoryTest.php @@ -139,6 +139,10 @@ public function bar() $this->assertSame([], $context->getNamespaceAliases()); } + /** + * @covers ::createForNamespace + * @uses phpDocumentor\Reflection\Types\Context + */ public function testTraitContainsClosureWithUseStatement() : void { $php = '