1414use PHPUnit \Framework \TestCase ;
1515use SebastianBergmann \CodeCoverage \TestFixture \Target \TargetClass ;
1616use SebastianBergmann \CodeCoverage \TestFixture \Target \TargetInterface ;
17+ use SebastianBergmann \CodeCoverage \TestFixture \Target \TraitOne ;
1718
1819#[CoversClass(Target::class)]
1920#[CoversClass(Class_::class)]
2223#[CoversClass(Function_::class)]
2324#[CoversClass(Method::class)]
2425#[CoversClass(Namespace_::class)]
26+ #[CoversClass(Trait_::class)]
2527#[Small]
2628final class TargetTest extends TestCase
2729{
@@ -37,6 +39,7 @@ public function testCanBeClass(): void
3739 $ this ->assertFalse ($ target ->isFunction ());
3840 $ this ->assertFalse ($ target ->isMethod ());
3941 $ this ->assertFalse ($ target ->isNamespace ());
42+ $ this ->assertFalse ($ target ->isTrait ());
4043
4144 $ this ->assertSame ($ className , $ target ->className ());
4245 $ this ->assertSame ('classes ' , $ target ->key ());
@@ -56,6 +59,7 @@ public function testCanBeClassesThatExtendClass(): void
5659 $ this ->assertFalse ($ target ->isFunction ());
5760 $ this ->assertFalse ($ target ->isMethod ());
5861 $ this ->assertFalse ($ target ->isNamespace ());
62+ $ this ->assertFalse ($ target ->isTrait ());
5963
6064 $ this ->assertSame ($ className , $ target ->className ());
6165 $ this ->assertSame ('classesThatExtendClass ' , $ target ->key ());
@@ -75,6 +79,7 @@ public function testCanBeClassesThatImplementInterface(): void
7579 $ this ->assertFalse ($ target ->isFunction ());
7680 $ this ->assertFalse ($ target ->isMethod ());
7781 $ this ->assertFalse ($ target ->isNamespace ());
82+ $ this ->assertFalse ($ target ->isTrait ());
7883
7984 $ this ->assertSame ($ interfaceName , $ target ->interfaceName ());
8085 $ this ->assertSame ('classesThatImplementInterface ' , $ target ->key ());
@@ -94,6 +99,7 @@ public function testCanBeFunction(): void
9499 $ this ->assertTrue ($ target ->isFunction ());
95100 $ this ->assertFalse ($ target ->isMethod ());
96101 $ this ->assertFalse ($ target ->isNamespace ());
102+ $ this ->assertFalse ($ target ->isTrait ());
97103
98104 $ this ->assertSame ($ functionName , $ target ->functionName ());
99105 $ this ->assertSame ('functions ' , $ target ->key ());
@@ -114,6 +120,7 @@ public function testCanBeMethod(): void
114120 $ this ->assertFalse ($ target ->isFunction ());
115121 $ this ->assertTrue ($ target ->isMethod ());
116122 $ this ->assertFalse ($ target ->isNamespace ());
123+ $ this ->assertFalse ($ target ->isTrait ());
117124
118125 $ this ->assertSame ($ className , $ target ->className ());
119126 $ this ->assertSame ($ methodName , $ target ->methodName ());
@@ -134,10 +141,31 @@ public function testCanBeNamespace(): void
134141 $ this ->assertFalse ($ target ->isFunction ());
135142 $ this ->assertFalse ($ target ->isMethod ());
136143 $ this ->assertTrue ($ target ->isNamespace ());
144+ $ this ->assertFalse ($ target ->isTrait ());
137145
138146 $ this ->assertSame ($ namespace , $ target ->namespace ());
139147 $ this ->assertSame ('namespaces ' , $ target ->key ());
140148 $ this ->assertSame ($ namespace , $ target ->target ());
141149 $ this ->assertSame ('Namespace ' . $ namespace , $ target ->description ());
142150 }
151+
152+ public function testCanBeTrait (): void
153+ {
154+ $ traitName = TraitOne::class;
155+
156+ $ target = Target::forTrait ($ traitName );
157+
158+ $ this ->assertTrue ($ target ->isTrait ());
159+ $ this ->assertFalse ($ target ->isClass ());
160+ $ this ->assertFalse ($ target ->isClassesThatExtendClass ());
161+ $ this ->assertFalse ($ target ->isClassesThatImplementInterface ());
162+ $ this ->assertFalse ($ target ->isFunction ());
163+ $ this ->assertFalse ($ target ->isMethod ());
164+ $ this ->assertFalse ($ target ->isNamespace ());
165+
166+ $ this ->assertSame ($ traitName , $ target ->traitName ());
167+ $ this ->assertSame ('traits ' , $ target ->key ());
168+ $ this ->assertSame ($ traitName , $ target ->target ());
169+ $ this ->assertSame ('Trait ' . $ traitName , $ target ->description ());
170+ }
143171}
0 commit comments