Closed
Description
Q | A |
---|---|
PHPUnit version | 2bc4a05 |
PHP version | 7.4.16 |
Installation Method | Git clone |
Summary
I am aware that using generators in count related assertions is deprecated, but there seems to be some cases where it has not been deprecated properly(?)
Current behavior
assertNotEmpty with empty generator, no warning
self::assertNotEmpty((fn(): Generator => yield [])());
#> Success
❌ Should trigger warning as this doesn't even work.
assertNotEmpty with non-empty generator
self::assertNotEmpty((fn(): Generator => yield from ['ok'])())
#> Success
❌ Should trigger warning.
assertEmpty with empty generator
self::assertEmpty((fn(): Generator => yield [])());
#> Failed asserting that an object is empty.
🆗 Could argue that this is ok as it sort-of says that Generators are not supported.
assertCount with empty generator
self::assertCount(0, (fn() => yield [])());
#> Failed asserting that actual size 0 matches expected size 0.
❓ Weird.
assertCount with generator where assertion fails
This is just weird and might not be relevant.
self::assertCount(0, (fn() => yield from ['foo'])());
#> Failed asserting that actual size 0 matches expected size 0.
🆗 Asserting count is 1 will make this test pass and a warning will be sent.
Expected behavior
Warning with the message:
Passing an argument of type Generator for the $haystack parameter is deprecated. Support for this will be removed in PHPUnit 11.
Related to #4568