Skip to content

Commit

Permalink
Closes #6046
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 28, 2024
1 parent 2afa616 commit 72de5c0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ChangeLog-11.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ All notable changes of the PHPUnit 11.5 release series are documented in this fi
* [#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
* `TestRunner\ChildProcessStarted` and `TestRunner\ChildProcessFinished` events

### Deprecated

* [#6046](https://github.com/sebastianbergmann/phpunit/issues/6046): Support for using `assertContainsOnly()` (and `assertNotContainsOnly()`) with classes and interfaces

[11.5.0]: https://github.com/sebastianbergmann/phpunit/compare/11.4...11.5
9 changes: 5 additions & 4 deletions DEPRECATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ This functionality is currently [hard-deprecated](https://phpunit.de/backward-co

#### Assertions, Constraints, and Expectations

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

#### Test Double API

Expand Down
14 changes: 14 additions & 0 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ final public static function assertContainsOnly(string $type, iterable $haystack
$isNativeType = self::isNativeType($type);
}

if (!$isNativeType || class_exists($type) || interface_exists($type)) {
Event\Facade::emitter()->testTriggeredPhpunitDeprecation(
null,
'Using assertContainsOnly() with classes or interfaces is deprecated. Support for this will be removed in PHPUnit 12. Please use assertContainsOnlyInstancesOf() instead.',
);
}

self::assertThat(
$haystack,
new TraversableContainsOnly(
Expand Down Expand Up @@ -325,6 +332,13 @@ final public static function assertNotContainsOnly(string $type, iterable $hayst
$isNativeType = self::isNativeType($type);
}

if (!$isNativeType || class_exists($type) || interface_exists($type)) {
Event\Facade::emitter()->testTriggeredPhpunitDeprecation(
null,
'Using assertNotContainsOnly() with classes or interfaces is deprecated. Support for this will be removed in PHPUnit 12. Please use assertContainsOnlyInstancesOf() instead.',
);
}

self::assertThat(
$haystack,
new LogicalNot(
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Framework/Assert/assertContainsOnlyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use function fopen;
use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\Attributes\TestDox;
use stdClass;
Expand All @@ -20,6 +21,7 @@
#[CoversMethod(Assert::class, 'isNativeType')]
#[TestDox('assertContainsOnly()')]
#[Small]
#[IgnorePhpunitDeprecations]
final class assertContainsOnlyTest extends TestCase
{
/**
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Framework/Assert/assertNotContainsOnlyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\Attributes\DataProviderExternal;
use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\Attributes\TestDox;

#[CoversMethod(Assert::class, 'assertNotContainsOnly')]
#[CoversMethod(Assert::class, 'isNativeType')]
#[TestDox('assertNotContainsOnly()')]
#[Small]
#[IgnorePhpunitDeprecations]
final class assertNotContainsOnlyTest extends TestCase
{
#[DataProviderExternal(assertContainsOnlyTest::class, 'failureProvider')]
Expand Down

0 comments on commit 72de5c0

Please sign in to comment.