Skip to content

Commit 17bbefa

Browse files
Document the fact that CoversClass and UsesClass implicitly target traits used by the targeted classes
1 parent 4f8a0e2 commit 17bbefa

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture;
11+
12+
final class CoveredClassUsingCoveredTrait
13+
{
14+
use CoveredTrait;
15+
16+
public function publicMethod(): void
17+
{
18+
}
19+
20+
protected function protectedMethod(): void
21+
{
22+
}
23+
24+
private function privateMethod(): void
25+
{
26+
}
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture;
11+
12+
use PHPUnit\Framework\Attributes\CoversClass;
13+
use PHPUnit\Framework\Attributes\UsesClass;
14+
use PHPUnit\Framework\TestCase;
15+
16+
#[CoversClass(CoveredClassUsingCoveredTrait::class)]
17+
#[UsesClass(CoveredClassUsingCoveredTrait::class)]
18+
final class CoveredClassUsingCoveredTraitTest extends TestCase
19+
{
20+
public function testSomething(): void
21+
{
22+
}
23+
}

tests/unit/Metadata/Api/CodeCoverageTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use PHPUnit\TestFixture\CoverageNoneTest;
3737
use PHPUnit\TestFixture\CoverageTraitMethodTest;
3838
use PHPUnit\TestFixture\CoverageTraitTest;
39+
use PHPUnit\TestFixture\CoveredClassUsingCoveredTraitTest;
3940
use PHPUnit\TestFixture\InterfaceAsTargetWithAttributeTest;
4041
use PHPUnit\TestFixture\InterfaceTargetTest;
4142
use PHPUnit\TestFixture\InvalidClassTargetWithAnnotationTest;
@@ -129,6 +130,15 @@ public static function linesToBeCoveredProvider(): array
129130
'testSomething',
130131
],
131132

133+
[
134+
[
135+
TEST_FILES_PATH . 'CoveredClassUsingCoveredTrait.php' => range(12, 27),
136+
TEST_FILES_PATH . 'CoveredTrait.php' => range(12, 18),
137+
],
138+
CoveredClassUsingCoveredTraitTest::class,
139+
'testSomething',
140+
],
141+
132142
[
133143
[
134144
TEST_FILES_PATH . 'CoveredClass.php' => range(14, 18),
@@ -296,6 +306,15 @@ public static function linesToBeUsedProvider(): array
296306
'testSomething',
297307
],
298308

309+
[
310+
[
311+
TEST_FILES_PATH . 'CoveredClassUsingCoveredTrait.php' => range(12, 27),
312+
TEST_FILES_PATH . 'CoveredTrait.php' => range(12, 18),
313+
],
314+
CoveredClassUsingCoveredTraitTest::class,
315+
'testSomething',
316+
],
317+
299318
[
300319
[
301320
TEST_FILES_PATH . 'CoveredFunction.php' => range(10, 12),

0 commit comments

Comments
 (0)