Skip to content

Commit 7372585

Browse files
Closes #3194
1 parent 7362c90 commit 7372585

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

ChangeLog-7.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ All notable changes of the PHPUnit 7.3 release series are documented in this fil
1515
* The `--order-by=depends` CLI option should now be used instead of `--resolve-dependencies`
1616
* The `--order-by=reverse` CLI option should now be used instead of `--reverse-order`
1717
* Implemented [#3161](https://github.com/sebastianbergmann/phpunit/pull/3161): Support for indexed arrays in `PHPUnit\Framework\Constraint\ArraySubset`
18+
* Implemented [#3194](https://github.com/sebastianbergmann/phpunit/issues/3194): `@covers class` (and `@uses class`) should include traits used by class
1819

1920
[7.3.0]: https://github.com/sebastianbergmann/phpunit/compare/7.2...7.3.0
2021

src/Util/Test.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,14 @@ private static function resolveReflectionObjectsToLines(array $reflectors): arra
10391039
{
10401040
$result = [];
10411041

1042+
foreach ($reflectors as $reflector) {
1043+
if ($reflector instanceof ReflectionClass) {
1044+
foreach ($reflector->getTraits() as $trait) {
1045+
$reflectors[] = $trait;
1046+
}
1047+
}
1048+
}
1049+
10421050
foreach ($reflectors as $reflector) {
10431051
$filename = $reflector->getFileName();
10441052

tests/Util/TestTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,4 +1028,34 @@ public function testParseTestMethodAnnotationsIncorporatesTraits(): void
10281028
$this->assertArrayHasKey('theClassAnnotation', $result['class']);
10291029
$this->assertArrayHasKey('theTraitAnnotation', $result['class']);
10301030
}
1031+
1032+
public function testCoversAnnotationIncludesTraitsUsedByClass(): void
1033+
{
1034+
$this->assertSame(
1035+
[
1036+
'/usr/local/src/phpunit/tests/_files/3194.php' => [
1037+
0 => 13,
1038+
1 => 14,
1039+
2 => 15,
1040+
3 => 16,
1041+
4 => 17,
1042+
5 => 18,
1043+
6 => 19,
1044+
7 => 20,
1045+
8 => 21,
1046+
9 => 5,
1047+
10 => 6,
1048+
11 => 7,
1049+
12 => 8,
1050+
13 => 9,
1051+
14 => 10,
1052+
15 => 11
1053+
]
1054+
],
1055+
Test::getLinesToBeCovered(
1056+
\Test3194::class,
1057+
'testOne'
1058+
)
1059+
);
1060+
}
10311061
}

tests/_files/3194.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types=1);
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
trait T3194
6+
{
7+
public function doSomethingElse(): bool
8+
{
9+
return true;
10+
}
11+
}
12+
13+
final class C3194
14+
{
15+
use T3194;
16+
17+
public function doSomething(): bool
18+
{
19+
return $this->doSomethingElse();
20+
}
21+
}
22+
23+
/**
24+
* @covers C3194
25+
*/
26+
final class Test3194 extends TestCase
27+
{
28+
public function testOne(): void
29+
{
30+
$o = new C;
31+
32+
$this->assertTrue($o->doSomething());
33+
}
34+
}

0 commit comments

Comments
 (0)