Skip to content

Support for generators in assertCount() etc. is not marked as deprecated in PHPUnit 9.6 #4618

Closed
@eigan

Description

@eigan
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

Metadata

Metadata

Labels

feature/assertionIssues related to assertions and expectationstype/bugSomething is brokentype/deprecationSomething will be/is deprecatedversion/9Something affects PHPUnit 9

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions