-
-
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
Expected size is wrong in assertCount error message #3302
Comments
I cannot reproduce this: <?php declare(strict_types=1);
class Test extends PHPUnit\Framework\TestCase
{
public function testOne(): void
{
$a = [1, 2, 3];
$this->assertCount(4, $a);
}
}
|
My input is a |
Thank you for your report. Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting. Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue. |
public function testGenerator()
{
$generator = static function () {
yield 1;
yield 2;
yield 3;
};
static::assertCount(3, $generator());
static::assertCount(4, $generator());
} |
|
AFAICS, the only sensible thing to do here would be to disallow |
The issue does not depend on calling assertCount twice.
That assert alone does the trick. You will get the error saying 0 does not match 4. |
Disallowing
|
Sorry for bringing more issue rather than a solution, but besides generators, there is the same problem with other non-countable, forward-only (non-rewindable) iterators/traversables, e.g.: assertCount(4, new \NoRewindIterator(new \ArrayIterator([1, 2, 3]))); or things like |
The fix that is up should also take care of those, see #3304 |
This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it has not had activity since it was marked as stale. Thank you for your contributions. |
!stale |
I have this and the test passes:
I changed it from 6 to 5 to verify the test is being run
Got error
While I expected to get
The text was updated successfully, but these errors were encountered: