Skip to content

Commit b557d51

Browse files
Closes #4618
1 parent 0154749 commit b557d51

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

ChangeLog-9.6.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 9.6 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [9.6.2] - 2023-MM-DD
6+
7+
### Fixed
8+
9+
* [#4618](https://github.com/sebastianbergmann/phpunit/issues/4618): Support for generators in `assertCount()` etc. is not marked as deprecated in PHPUnit 9.6
10+
511
## [9.6.1] - 2023-02-03
612

713
### Fixed
@@ -18,5 +24,6 @@ All notable changes of the PHPUnit 9.6 release series are documented in this fil
1824
* [#5064](https://github.com/sebastianbergmann/phpunit/issues/5064): Deprecate `PHPUnit\Framework\TestCase::getMockClass()`
1925
* [#5132](https://github.com/sebastianbergmann/phpunit/issues/5132): Deprecate `Test` suffix for abstract test case classes
2026

27+
[9.6.2]: https://github.com/sebastianbergmann/phpunit/compare/9.6.1...9.6
2128
[9.6.1]: https://github.com/sebastianbergmann/phpunit/compare/9.6.0...9.6.1
2229
[9.6.0]: https://github.com/sebastianbergmann/phpunit/compare/9.5.28...9.6.0

src/Framework/Assert.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use DOMAttr;
3838
use DOMDocument;
3939
use DOMElement;
40+
use Generator;
4041
use PHPUnit\Framework\Constraint\ArrayHasKey;
4142
use PHPUnit\Framework\Constraint\Callback;
4243
use PHPUnit\Framework\Constraint\ClassHasAttribute;
@@ -278,6 +279,10 @@ public static function assertNotContainsOnly(string $type, iterable $haystack, ?
278279
*/
279280
public static function assertCount(int $expectedCount, $haystack, string $message = ''): void
280281
{
282+
if ($haystack instanceof Generator) {
283+
self::createWarning('Passing an argument of type Generator for the $haystack parameter is deprecated. Support for this will be removed in PHPUnit 10.');
284+
}
285+
281286
if (!$haystack instanceof Countable && !is_iterable($haystack)) {
282287
throw InvalidArgumentException::create(2, 'countable or iterable');
283288
}
@@ -300,6 +305,10 @@ public static function assertCount(int $expectedCount, $haystack, string $messag
300305
*/
301306
public static function assertNotCount(int $expectedCount, $haystack, string $message = ''): void
302307
{
308+
if ($haystack instanceof Generator) {
309+
self::createWarning('Passing an argument of type Generator for the $haystack parameter is deprecated. Support for this will be removed in PHPUnit 10.');
310+
}
311+
303312
if (!$haystack instanceof Countable && !is_iterable($haystack)) {
304313
throw InvalidArgumentException::create(2, 'countable or iterable');
305314
}
@@ -451,6 +460,10 @@ public static function assertObjectEquals(object $expected, object $actual, stri
451460
*/
452461
public static function assertEmpty($actual, string $message = ''): void
453462
{
463+
if ($actual instanceof Generator) {
464+
self::createWarning('Passing an argument of type Generator for the $actual parameter is deprecated. Support for this will be removed in PHPUnit 10.');
465+
}
466+
454467
static::assertThat($actual, static::isEmpty(), $message);
455468
}
456469

@@ -464,6 +477,10 @@ public static function assertEmpty($actual, string $message = ''): void
464477
*/
465478
public static function assertNotEmpty($actual, string $message = ''): void
466479
{
480+
if ($actual instanceof Generator) {
481+
self::createWarning('Passing an argument of type Generator for the $actual parameter is deprecated. Support for this will be removed in PHPUnit 10.');
482+
}
483+
467484
static::assertThat($actual, static::logicalNot(static::isEmpty()), $message);
468485
}
469486

@@ -1925,6 +1942,14 @@ public static function assertNotRegExp(string $pattern, string $string, string $
19251942
*/
19261943
public static function assertSameSize($expected, $actual, string $message = ''): void
19271944
{
1945+
if ($expected instanceof Generator) {
1946+
self::createWarning('Passing an argument of type Generator for the $expected parameter is deprecated. Support for this will be removed in PHPUnit 10.');
1947+
}
1948+
1949+
if ($actual instanceof Generator) {
1950+
self::createWarning('Passing an argument of type Generator for the $actual parameter is deprecated. Support for this will be removed in PHPUnit 10.');
1951+
}
1952+
19281953
if (!$expected instanceof Countable && !is_iterable($expected)) {
19291954
throw InvalidArgumentException::create(1, 'countable or iterable');
19301955
}
@@ -1953,6 +1978,14 @@ public static function assertSameSize($expected, $actual, string $message = ''):
19531978
*/
19541979
public static function assertNotSameSize($expected, $actual, string $message = ''): void
19551980
{
1981+
if ($expected instanceof Generator) {
1982+
self::createWarning('Passing an argument of type Generator for the $expected parameter is deprecated. Support for this will be removed in PHPUnit 10.');
1983+
}
1984+
1985+
if ($actual instanceof Generator) {
1986+
self::createWarning('Passing an argument of type Generator for the $actual parameter is deprecated. Support for this will be removed in PHPUnit 10.');
1987+
}
1988+
19561989
if (!$expected instanceof Countable && !is_iterable($expected)) {
19571990
throw InvalidArgumentException::create(1, 'countable or iterable');
19581991
}

0 commit comments

Comments
 (0)