From b557d51b53bbd90003b9e2cf141c89fe424b077f Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sat, 4 Feb 2023 07:27:31 +0100 Subject: [PATCH] Closes #4618 --- ChangeLog-9.6.md | 7 +++++++ src/Framework/Assert.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/ChangeLog-9.6.md b/ChangeLog-9.6.md index 258e386c67e..ae8deb41c82 100644 --- a/ChangeLog-9.6.md +++ b/ChangeLog-9.6.md @@ -2,6 +2,12 @@ All notable changes of the PHPUnit 9.6 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [9.6.2] - 2023-MM-DD + +### Fixed + +* [#4618](https://github.com/sebastianbergmann/phpunit/issues/4618): Support for generators in `assertCount()` etc. is not marked as deprecated in PHPUnit 9.6 + ## [9.6.1] - 2023-02-03 ### Fixed @@ -18,5 +24,6 @@ All notable changes of the PHPUnit 9.6 release series are documented in this fil * [#5064](https://github.com/sebastianbergmann/phpunit/issues/5064): Deprecate `PHPUnit\Framework\TestCase::getMockClass()` * [#5132](https://github.com/sebastianbergmann/phpunit/issues/5132): Deprecate `Test` suffix for abstract test case classes +[9.6.2]: https://github.com/sebastianbergmann/phpunit/compare/9.6.1...9.6 [9.6.1]: https://github.com/sebastianbergmann/phpunit/compare/9.6.0...9.6.1 [9.6.0]: https://github.com/sebastianbergmann/phpunit/compare/9.5.28...9.6.0 diff --git a/src/Framework/Assert.php b/src/Framework/Assert.php index a8e632329ce..156220a5105 100644 --- a/src/Framework/Assert.php +++ b/src/Framework/Assert.php @@ -37,6 +37,7 @@ use DOMAttr; use DOMDocument; use DOMElement; +use Generator; use PHPUnit\Framework\Constraint\ArrayHasKey; use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\Constraint\ClassHasAttribute; @@ -278,6 +279,10 @@ public static function assertNotContainsOnly(string $type, iterable $haystack, ? */ public static function assertCount(int $expectedCount, $haystack, string $message = ''): void { + if ($haystack instanceof Generator) { + self::createWarning('Passing an argument of type Generator for the $haystack parameter is deprecated. Support for this will be removed in PHPUnit 10.'); + } + if (!$haystack instanceof Countable && !is_iterable($haystack)) { throw InvalidArgumentException::create(2, 'countable or iterable'); } @@ -300,6 +305,10 @@ public static function assertCount(int $expectedCount, $haystack, string $messag */ public static function assertNotCount(int $expectedCount, $haystack, string $message = ''): void { + if ($haystack instanceof Generator) { + self::createWarning('Passing an argument of type Generator for the $haystack parameter is deprecated. Support for this will be removed in PHPUnit 10.'); + } + if (!$haystack instanceof Countable && !is_iterable($haystack)) { throw InvalidArgumentException::create(2, 'countable or iterable'); } @@ -451,6 +460,10 @@ public static function assertObjectEquals(object $expected, object $actual, stri */ public static function assertEmpty($actual, string $message = ''): void { + if ($actual instanceof Generator) { + self::createWarning('Passing an argument of type Generator for the $actual parameter is deprecated. Support for this will be removed in PHPUnit 10.'); + } + static::assertThat($actual, static::isEmpty(), $message); } @@ -464,6 +477,10 @@ public static function assertEmpty($actual, string $message = ''): void */ public static function assertNotEmpty($actual, string $message = ''): void { + if ($actual instanceof Generator) { + self::createWarning('Passing an argument of type Generator for the $actual parameter is deprecated. Support for this will be removed in PHPUnit 10.'); + } + static::assertThat($actual, static::logicalNot(static::isEmpty()), $message); } @@ -1925,6 +1942,14 @@ public static function assertNotRegExp(string $pattern, string $string, string $ */ public static function assertSameSize($expected, $actual, string $message = ''): void { + if ($expected instanceof Generator) { + self::createWarning('Passing an argument of type Generator for the $expected parameter is deprecated. Support for this will be removed in PHPUnit 10.'); + } + + if ($actual instanceof Generator) { + self::createWarning('Passing an argument of type Generator for the $actual parameter is deprecated. Support for this will be removed in PHPUnit 10.'); + } + if (!$expected instanceof Countable && !is_iterable($expected)) { throw InvalidArgumentException::create(1, 'countable or iterable'); } @@ -1953,6 +1978,14 @@ public static function assertSameSize($expected, $actual, string $message = ''): */ public static function assertNotSameSize($expected, $actual, string $message = ''): void { + if ($expected instanceof Generator) { + self::createWarning('Passing an argument of type Generator for the $expected parameter is deprecated. Support for this will be removed in PHPUnit 10.'); + } + + if ($actual instanceof Generator) { + self::createWarning('Passing an argument of type Generator for the $actual parameter is deprecated. Support for this will be removed in PHPUnit 10.'); + } + if (!$expected instanceof Countable && !is_iterable($expected)) { throw InvalidArgumentException::create(1, 'countable or iterable'); }