Skip to content

Commit

Permalink
Merge branch '11.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 28, 2024
2 parents ecb3aed + 72de5c0 commit 43368e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,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 @@ -324,6 +331,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 43368e6

Please sign in to comment.