Skip to content

Commit ab4e40f

Browse files
Revert deprecation of targeting traits
1 parent a04d910 commit ab4e40f

13 files changed

+5
-344
lines changed

ChangeLog-11.5.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
44

55
## [11.5.4] - 2025-MM-DD
66

7+
### Changed
8+
9+
* [#5958](https://github.com/sebastianbergmann/phpunit/issues/5958): Support for `#[CoversTrait]` and `#[UsesTrait]` attributes is no longer deprecated
10+
* [#5960](https://github.com/sebastianbergmann/phpunit/issues/5960): Support for targeting trait methods with the `#[CoversMethod]` and `#[UsesMethod]` attributes is no longer deprecated
11+
712
### Fixed
813

914
* [#6103](https://github.com/sebastianbergmann/phpunit/issues/6103): Output from test run in separate process is printed twice

DEPRECATIONS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ This functionality is currently [hard-deprecated](https://phpunit.de/backward-co
5959
| [#5216](https://github.com/sebastianbergmann/phpunit/issues/5216) | `TestCase::setLocale()` | 10.3.0 | |
6060
| [#5800](https://github.com/sebastianbergmann/phpunit/issues/5800) | Targeting traits with `#[CoversClass]` and `#[UsesClass]` | 11.2.0 | `#[CoversClass]` and `#[UsesClass]` also target the traits used by the targeted classes |
6161
| [#5951](https://github.com/sebastianbergmann/phpunit/issues/5951) | `includeUncoveredFiles` configuration option | 11.4.0 | |
62-
| [#5958](https://github.com/sebastianbergmann/phpunit/issues/5958) | `#[CoversTrait]` and `#[UsesTrait]` attributes | 11.4.0 | `#[CoversClass]` and `#[UsesClass]` also target the traits used by the targeted classes |
6362
| [#5960](https://github.com/sebastianbergmann/phpunit/issues/5960) | Targeting traits with `#[CoversMethod]` and `#[UsesMethod]` | 11.4.0 | |
6463

6564
## Soft Deprecations

src/Framework/Attributes/CoversTrait.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* @immutable
1616
*
1717
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
18-
*
19-
* @deprecated
2018
*/
2119
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
2220
final readonly class CoversTrait

src/Framework/Attributes/UsesTrait.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* @immutable
1616
*
1717
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
18-
*
19-
* @deprecated
2018
*/
2119
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
2220
final readonly class UsesTrait

src/Metadata/Api/CodeCoverage.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use function sprintf;
1717
use function str_starts_with;
1818
use function trait_exists;
19-
use PHPUnit\Event\Facade as EventFacade;
2019
use PHPUnit\Framework\CodeCoverageException;
2120
use PHPUnit\Framework\InvalidCoversTargetException;
2221
use PHPUnit\Metadata\Covers;
@@ -273,42 +272,6 @@ private function names(CoversClass|CoversFunction|CoversMethod|CoversTrait|UsesC
273272
$name = $metadata->asStringForCodeUnitMapper();
274273
$names = [$name];
275274

276-
if ($metadata->isCoversTrait()) {
277-
EventFacade::emitter()->testRunnerTriggeredDeprecation(
278-
sprintf(
279-
'Targeting a trait such as %s with #[CoversTrait] is deprecated. The traits used by the class(es) you target with #[CoversClass] will be targeted as well.',
280-
$names[0],
281-
),
282-
);
283-
}
284-
285-
if ($metadata->isUsesTrait()) {
286-
EventFacade::emitter()->testRunnerTriggeredDeprecation(
287-
sprintf(
288-
'Targeting a trait such as %s with #[UsesTrait] is deprecated. The traits used by the class(es) you target with #[UsesClass] will be targeted as well.',
289-
$names[0],
290-
),
291-
);
292-
}
293-
294-
if ($metadata->isCoversMethod() && trait_exists($metadata->className())) {
295-
EventFacade::emitter()->testRunnerTriggeredDeprecation(
296-
sprintf(
297-
'Targeting a trait such as %s with #[CoversMethod] is deprecated.',
298-
$metadata->className(),
299-
),
300-
);
301-
}
302-
303-
if ($metadata->isUsesMethod() && trait_exists($metadata->className())) {
304-
EventFacade::emitter()->testRunnerTriggeredDeprecation(
305-
sprintf(
306-
'Targeting a trait such as %s with #[UsesMethod] is deprecated.',
307-
$metadata->className(),
308-
),
309-
);
310-
}
311-
312275
if ($metadata->isCoversClass() || $metadata->isUsesClass()) {
313276
if (isset($this->withParents[$name])) {
314277
return $this->withParents[$name];
@@ -334,24 +297,6 @@ private function names(CoversClass|CoversFunction|CoversMethod|CoversTrait|UsesC
334297

335298
assert(class_exists($names[0]) || trait_exists($names[0]));
336299

337-
if ($metadata->isCoversClass() && trait_exists($names[0])) {
338-
EventFacade::emitter()->testRunnerTriggeredDeprecation(
339-
sprintf(
340-
'Targeting a trait such as %s with #[CoversClass] is deprecated. The traits used by the class(es) you target with #[CoversClass] will be targeted as well.',
341-
$names[0],
342-
),
343-
);
344-
}
345-
346-
if ($metadata->isUsesClass() && trait_exists($names[0])) {
347-
EventFacade::emitter()->testRunnerTriggeredDeprecation(
348-
sprintf(
349-
'Targeting a trait such as %s with #[UsesClass] is deprecated. The traits used by the class(es) you target with #[UsesClass] will be targeted as well.',
350-
$names[0],
351-
),
352-
);
353-
}
354-
355300
$reflector = new ReflectionClass($name);
356301

357302
while ($reflector = $reflector->getParentClass()) {

tests/end-to-end/_files/TraitTargetedWithCoversMethodTest.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/end-to-end/_files/TraitTargetedWithUsesMethodTest.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/end-to-end/metadata/targeting-traits-with-coversclass-attribute-is-deprecated.phpt

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/end-to-end/metadata/targeting-traits-with-coversmethod-attribute-is-deprecated.phpt

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/end-to-end/metadata/targeting-traits-with-coverstrait-attribute-is-deprecated.phpt

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)