Skip to content

Commit

Permalink
Closes #4618
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 4, 2023
1 parent 0154749 commit b557d51
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-9.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
33 changes: 33 additions & 0 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
Expand All @@ -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');
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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');
}
Expand Down

0 comments on commit b557d51

Please sign in to comment.