15
15
use PhpParser \NodeVisitor \ParentConnectingVisitor ;
16
16
use PhpParser \ParserFactory ;
17
17
use PHPUnit \Framework \TestCase ;
18
- use SebastianBergmann \CodeCoverage \ClassThatUsesAnonymousClass \TestFixture \ClassThatUsesAnonymousClass ;
18
+ use SebastianBergmann \CodeCoverage \TestFixture \ClassThatUsesAnonymousClass ;
19
+ use SebastianBergmann \CodeCoverage \TestFixture \ClassWithNameThatIsPartOfItsNamespacesName \ClassWithNameThatIsPartOfItsNamespacesName ;
19
20
20
21
/**
21
22
* @covers \SebastianBergmann\CodeCoverage\StaticAnalysis\CodeUnitFindingVisitor
@@ -55,7 +56,7 @@ public function testDoesNotFindAnonymousClass(): void
55
56
56
57
$ this ->assertSame ('ClassThatUsesAnonymousClass ' , $ class ['name ' ]);
57
58
$ this ->assertSame (ClassThatUsesAnonymousClass::class, $ class ['namespacedName ' ]);
58
- $ this ->assertSame ('SebastianBergmann\CodeCoverage\ClassThatUsesAnonymousClass\ TestFixture ' , $ class ['namespace ' ]);
59
+ $ this ->assertSame ('SebastianBergmann\CodeCoverage\TestFixture ' , $ class ['namespace ' ]);
59
60
$ this ->assertSame (4 , $ class ['startLine ' ]);
60
61
$ this ->assertSame (17 , $ class ['endLine ' ]);
61
62
@@ -71,4 +72,40 @@ public function testDoesNotFindAnonymousClass(): void
71
72
$ this ->assertSame (16 , $ method ['endLine ' ]);
72
73
$ this ->assertSame (1 , $ method ['ccn ' ]);
73
74
}
75
+
76
+ /**
77
+ * @ticket https://github.com/sebastianbergmann/php-code-coverage/pull/797
78
+ */
79
+ public function testHandlesClassWithNameThatIsPartOfItsNamespacesName (): void
80
+ {
81
+ $ nodes = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 )->parse (
82
+ file_get_contents (__DIR__ . '/../../_files/ClassWithNameThatIsPartOfItsNamespacesName.php ' )
83
+ );
84
+
85
+ assert ($ nodes !== null );
86
+
87
+ $ traverser = new NodeTraverser ;
88
+ $ codeUnitFindingVisitor = new CodeUnitFindingVisitor ;
89
+
90
+ $ traverser ->addVisitor (new NameResolver );
91
+ $ traverser ->addVisitor (new ParentConnectingVisitor );
92
+ $ traverser ->addVisitor ($ codeUnitFindingVisitor );
93
+
94
+ /* @noinspection UnusedFunctionResultInspection */
95
+ $ traverser ->traverse ($ nodes );
96
+
97
+ $ this ->assertEmpty ($ codeUnitFindingVisitor ->functions ());
98
+ $ this ->assertEmpty ($ codeUnitFindingVisitor ->traits ());
99
+
100
+ $ classes = $ codeUnitFindingVisitor ->classes ();
101
+
102
+ $ this ->assertCount (1 , $ classes );
103
+ $ this ->assertArrayHasKey (ClassWithNameThatIsPartOfItsNamespacesName::class, $ classes );
104
+
105
+ $ class = $ classes [ClassWithNameThatIsPartOfItsNamespacesName::class];
106
+
107
+ $ this ->assertSame ('ClassWithNameThatIsPartOfItsNamespacesName ' , $ class ['name ' ]);
108
+ $ this ->assertSame (ClassWithNameThatIsPartOfItsNamespacesName::class, $ class ['namespacedName ' ]);
109
+ $ this ->assertSame ('SebastianBergmann\CodeCoverage\TestFixture\ClassWithNameThatIsPartOfItsNamespacesName ' , $ class ['namespace ' ]);
110
+ }
74
111
}
0 commit comments