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

Shows incorrect failed message with closed Generator #5079

Closed
ssi-anik opened this issue Oct 13, 2022 · 1 comment
Closed

Shows incorrect failed message with closed Generator #5079

ssi-anik opened this issue Oct 13, 2022 · 1 comment
Labels
type/bug Something is broken

Comments

@ssi-anik
Copy link

Q A
PHPUnit version 9.5.25
PHP version 8.1.11
Installation Method Composer

Summary

When trying assertCount with a generator, a mismatch between the expected and generator count will show an invalid message. The reason is that the Generator is closed during the evaluation, and cannot get the count when generating the message.

Current behavior

Failed asserting that actual size 0 matches expected size EXPECTED_VALUE

How to reproduce

public function testGenerator () {
    $items = (function () {
        foreach (range(1, 10) as $item) {
            yield $item;
        }
    })();

    $this->assertCount(11, $items);
}

Expected behavior

Failed asserting that actual size ACTUAL_SIZE matches expected size EXPECTED_VALUE

@ssi-anik ssi-anik added the type/bug Something is broken label Oct 13, 2022
@sebastianbergmann
Copy link
Owner

Duplicate of #4271.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants