Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eigan opened this issue Mar 10, 2021 · 1 comment
Assignees
Labels
feature/assertion Issues related to assertions and expectations type/bug Something is broken type/deprecation Something will be/is deprecated version/9 Something affects PHPUnit 9

Comments

@eigan
Copy link

eigan commented Mar 10, 2021

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

@eigan eigan added the type/bug Something is broken label Mar 10, 2021
@sebastianbergmann sebastianbergmann added the feature/assertion Issues related to assertions and expectations label Mar 10, 2021
@sebastianbergmann
Copy link
Owner

These depecations were originally planned for PHPUnit 10 with removal of support for generators in the functionality in question planned for PHPUnit 11. However, this functionality was now already removed in PHPUnit 10.

This functionality needs to be marked as deprecated in PHPUnit 9.6.

@sebastianbergmann sebastianbergmann changed the title Weird behavior when sending empty generator Support for generators in assertCount() etc. is not marked as deprecated in PHPUnit 9.6 Feb 4, 2023
@sebastianbergmann sebastianbergmann self-assigned this Feb 4, 2023
@sebastianbergmann sebastianbergmann added type/deprecation Something will be/is deprecated version/9 Something affects PHPUnit 9 labels Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/assertion Issues related to assertions and expectations type/bug Something is broken type/deprecation Something will be/is deprecated version/9 Something affects PHPUnit 9
Projects
None yet
Development

No branches or pull requests

2 participants