diff --git a/ChangeLog-7.3.md b/ChangeLog-7.3.md index ab4e447e05c..cc0279bd92b 100644 --- a/ChangeLog-7.3.md +++ b/ChangeLog-7.3.md @@ -15,6 +15,7 @@ All notable changes of the PHPUnit 7.3 release series are documented in this fil * The `--order-by=depends` CLI option should now be used instead of `--resolve-dependencies` * The `--order-by=reverse` CLI option should now be used instead of `--reverse-order` * Implemented [#3161](https://github.com/sebastianbergmann/phpunit/pull/3161): Support for indexed arrays in `PHPUnit\Framework\Constraint\ArraySubset` +* Implemented [#3194](https://github.com/sebastianbergmann/phpunit/issues/3194): `@covers class` (and `@uses class`) should include traits used by class [7.3.0]: https://github.com/sebastianbergmann/phpunit/compare/7.2...7.3.0 diff --git a/src/Util/Test.php b/src/Util/Test.php index 7544de3ff87..1fd27a3d4c7 100644 --- a/src/Util/Test.php +++ b/src/Util/Test.php @@ -1039,6 +1039,14 @@ private static function resolveReflectionObjectsToLines(array $reflectors): arra { $result = []; + foreach ($reflectors as $reflector) { + if ($reflector instanceof ReflectionClass) { + foreach ($reflector->getTraits() as $trait) { + $reflectors[] = $trait; + } + } + } + foreach ($reflectors as $reflector) { $filename = $reflector->getFileName(); diff --git a/tests/Util/TestTest.php b/tests/Util/TestTest.php index a9873e122ca..aff4c7b20b3 100644 --- a/tests/Util/TestTest.php +++ b/tests/Util/TestTest.php @@ -1028,4 +1028,34 @@ public function testParseTestMethodAnnotationsIncorporatesTraits(): void $this->assertArrayHasKey('theClassAnnotation', $result['class']); $this->assertArrayHasKey('theTraitAnnotation', $result['class']); } + + public function testCoversAnnotationIncludesTraitsUsedByClass(): void + { + $this->assertSame( + [ + '/usr/local/src/phpunit/tests/_files/3194.php' => [ + 0 => 13, + 1 => 14, + 2 => 15, + 3 => 16, + 4 => 17, + 5 => 18, + 6 => 19, + 7 => 20, + 8 => 21, + 9 => 5, + 10 => 6, + 11 => 7, + 12 => 8, + 13 => 9, + 14 => 10, + 15 => 11 + ] + ], + Test::getLinesToBeCovered( + \Test3194::class, + 'testOne' + ) + ); + } } diff --git a/tests/_files/3194.php b/tests/_files/3194.php new file mode 100644 index 00000000000..14a2ea5ebc4 --- /dev/null +++ b/tests/_files/3194.php @@ -0,0 +1,34 @@ +doSomethingElse(); + } +} + +/** + * @covers C3194 + */ +final class Test3194 extends TestCase +{ + public function testOne(): void + { + $o = new C; + + $this->assertTrue($o->doSomething()); + } +}