Skip to content

Commit 72de5c0

Browse files
Closes #6046
1 parent 2afa616 commit 72de5c0

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

ChangeLog-11.5.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
1212
* [#5999](https://github.com/sebastianbergmann/phpunit/pull/5999): Do not run `CLEAN` section of PHPT test in separate process when it is free of side effects that modify the parent process
1313
* `TestRunner\ChildProcessStarted` and `TestRunner\ChildProcessFinished` events
1414

15+
### Deprecated
16+
17+
* [#6046](https://github.com/sebastianbergmann/phpunit/issues/6046): Support for using `assertContainsOnly()` (and `assertNotContainsOnly()`) with classes and interfaces
18+
1519
[11.5.0]: https://github.com/sebastianbergmann/phpunit/compare/11.4...11.5

DEPRECATIONS.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ This functionality is currently [hard-deprecated](https://phpunit.de/backward-co
88

99
#### Assertions, Constraints, and Expectations
1010

11-
| Issue | Description | Since | Replacement |
12-
|-------------------------------------------------------------------|------------------------------------------------|--------|-------------|
13-
| [#5472](https://github.com/sebastianbergmann/phpunit/issues/5472) | `TestCase::assertStringNotMatchesFormat()` | 10.4.0 | |
14-
| [#5472](https://github.com/sebastianbergmann/phpunit/issues/5472) | `TestCase::assertStringNotMatchesFormatFile()` | 10.4.0 | |
11+
| Issue | Description | Since | Replacement |
12+
|-------------------------------------------------------------------|----------------------------------------------------------------------------------------|--------|----------------------------------------------------------------------------|
13+
| [#5472](https://github.com/sebastianbergmann/phpunit/issues/5472) | `TestCase::assertStringNotMatchesFormat()` | 10.4.0 | |
14+
| [#5472](https://github.com/sebastianbergmann/phpunit/issues/5472) | `TestCase::assertStringNotMatchesFormatFile()` | 10.4.0 | |
15+
| [#6046](https://github.com/sebastianbergmann/phpunit/issues/6046) | Using `assertContainsOnly()` and `assertNotContainsOnly()` with classes and interfaces | 11.5.0 | `assertContainsOnlyInstancesOf()` and `assertNotContainsOnlyInstancesOf()` |
1516

1617
#### Test Double API
1718

src/Framework/Assert.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ final public static function assertContainsOnly(string $type, iterable $haystack
279279
$isNativeType = self::isNativeType($type);
280280
}
281281

282+
if (!$isNativeType || class_exists($type) || interface_exists($type)) {
283+
Event\Facade::emitter()->testTriggeredPhpunitDeprecation(
284+
null,
285+
'Using assertContainsOnly() with classes or interfaces is deprecated. Support for this will be removed in PHPUnit 12. Please use assertContainsOnlyInstancesOf() instead.',
286+
);
287+
}
288+
282289
self::assertThat(
283290
$haystack,
284291
new TraversableContainsOnly(
@@ -325,6 +332,13 @@ final public static function assertNotContainsOnly(string $type, iterable $hayst
325332
$isNativeType = self::isNativeType($type);
326333
}
327334

335+
if (!$isNativeType || class_exists($type) || interface_exists($type)) {
336+
Event\Facade::emitter()->testTriggeredPhpunitDeprecation(
337+
null,
338+
'Using assertNotContainsOnly() with classes or interfaces is deprecated. Support for this will be removed in PHPUnit 12. Please use assertContainsOnlyInstancesOf() instead.',
339+
);
340+
}
341+
328342
self::assertThat(
329343
$haystack,
330344
new LogicalNot(

tests/unit/Framework/Assert/assertContainsOnlyTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use function fopen;
1313
use PHPUnit\Framework\Attributes\CoversMethod;
1414
use PHPUnit\Framework\Attributes\DataProvider;
15+
use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations;
1516
use PHPUnit\Framework\Attributes\Small;
1617
use PHPUnit\Framework\Attributes\TestDox;
1718
use stdClass;
@@ -20,6 +21,7 @@
2021
#[CoversMethod(Assert::class, 'isNativeType')]
2122
#[TestDox('assertContainsOnly()')]
2223
#[Small]
24+
#[IgnorePhpunitDeprecations]
2325
final class assertContainsOnlyTest extends TestCase
2426
{
2527
/**

tests/unit/Framework/Assert/assertNotContainsOnlyTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111

1212
use PHPUnit\Framework\Attributes\CoversMethod;
1313
use PHPUnit\Framework\Attributes\DataProviderExternal;
14+
use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations;
1415
use PHPUnit\Framework\Attributes\Small;
1516
use PHPUnit\Framework\Attributes\TestDox;
1617

1718
#[CoversMethod(Assert::class, 'assertNotContainsOnly')]
1819
#[CoversMethod(Assert::class, 'isNativeType')]
1920
#[TestDox('assertNotContainsOnly()')]
2021
#[Small]
22+
#[IgnorePhpunitDeprecations]
2123
final class assertNotContainsOnlyTest extends TestCase
2224
{
2325
#[DataProviderExternal(assertContainsOnlyTest::class, 'failureProvider')]

0 commit comments

Comments
 (0)