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

PHPUnit fails to infer zero count for an EmptyIterator instance. #3743

Closed
sanmai opened this issue Jul 2, 2019 · 0 comments
Closed

PHPUnit fails to infer zero count for an EmptyIterator instance. #3743

sanmai opened this issue Jul 2, 2019 · 0 comments
Labels
type/bug Something is broken

Comments

@sanmai
Copy link
Contributor

sanmai commented Jul 2, 2019

Q A
PHPUnit version 8.2.3
PHP version 7.3.4
Installation Method Composer

This assertion should not fail:

$this->assertCount(0, new \EmptyIterator());

But it fails with an error:

1) Example::testEmptyIterator
BadMethodCallException: Accessing the key of an EmptyIterator

On the other hand this assertion works without a hitch:

$this->assertSame(0, iterator_count(new \EmptyIterator()));

These seems to be the problematic lines:

$key = $iterator->key();
$count = \iterator_count($iterator);
// Manually rewind $iterator to previous key, since iterator_count
// moves pointer.
if ($key !== null) {
$iterator->rewind();
while ($iterator->valid() && $key !== $iterator->key()) {
$iterator->next();
}
}
return $count;

A Travis CI build with this failure.

@sebastianbergmann sebastianbergmann added the type/bug Something is broken label Jul 2, 2019
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