-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix for assertCount expected size for Generator #3304
Fix for assertCount expected size for Generator #3304
Conversation
This does not solve the underlying problem that |
I don't know if it is possible in PHP.
Should we follow this path? If so, target it to |
@sebastianbergmann I don't see why that would be a problem. Going through a generator always does this in PHP, so it is expected behavior. Disallow it in assertCount would just force people to create such assertions themselves, which seems like loss-loss to me. |
From a developer perspective: whatever the underlying language feature does internally, I would expect an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider:
$gen2 = function () { yield 1; yield 2; };
$gen3 = function () { yield 1; yield 2; yield 3; };
$count2 = new Count(2);
Assert::assertTrue($count2->evaluate($gen2(), '', true));
Assert::assertFalse($count2->evaluate($gen3(), '', true)); // this should still work
$count3 = new Count(3);
Assert::assertFalse($count3->evaluate($gen2(), '', true));
Assert::assertTrue($count3->evaluate($gen3(), '', true)); // this should still work
Maybe need to reset $this->countOfGenerator = null;
at the beginning of function matches
?
Also please consider #3302 (comment) (i.e. there are non-Countable
, Traversable
things that are not instanceof Generator
but suffer the same kind of problem)...
I can confirm that this PR is breaking that behavior and does not clean up the already existing confusion between Generators and Iterables that cannot be rewinded. I'll submit a modified solution in a bit. Edit: here it is: #3316 |
Superseded by #3316. |
#3302