Skip to content

Commit

Permalink
Closes #3194
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 5, 2018
1 parent 7362c90 commit 7372585
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog-7.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

8 changes: 8 additions & 0 deletions src/Util/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
30 changes: 30 additions & 0 deletions tests/Util/TestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
);
}
}
34 changes: 34 additions & 0 deletions tests/_files/3194.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

use PHPUnit\Framework\TestCase;

trait T3194
{
public function doSomethingElse(): bool
{
return true;
}
}

final class C3194
{
use T3194;

public function doSomething(): bool
{
return $this->doSomethingElse();
}
}

/**
* @covers C3194
*/
final class Test3194 extends TestCase
{
public function testOne(): void
{
$o = new C;

$this->assertTrue($o->doSomething());
}
}

0 comments on commit 7372585

Please sign in to comment.