Skip to content

Commit

Permalink
Closes #3743
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 2, 2019
1 parent 1477fe4 commit 9faa89f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-7.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes of the PHPUnit 7.5 release series are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## [7.5.14] - 2019-MM-DD

### Fixed

* Fixed [#3743](https://github.com/sebastianbergmann/phpunit/issues/3743): `EmptyIterator` instances are not handled correctly by `Count` and `IsEmpty` constraints

## [7.5.13] - 2019-06-19

### Fixed
Expand Down Expand Up @@ -126,6 +132,7 @@ All notable changes of the PHPUnit 7.5 release series are documented in this fil
* Fixed [#3429](https://github.com/sebastianbergmann/phpunit/pull/3429): Inefficient loop in `getHookMethods()`
* Fixed [#3437](https://github.com/sebastianbergmann/phpunit/pull/3437): JUnit logger skips PHPT tests

[7.5.14]: https://github.com/sebastianbergmann/phpunit/compare/7.5.13...7.5.14
[7.5.13]: https://github.com/sebastianbergmann/phpunit/compare/7.5.12...7.5.13
[7.5.12]: https://github.com/sebastianbergmann/phpunit/compare/7.5.11...7.5.12
[7.5.11]: https://github.com/sebastianbergmann/phpunit/compare/7.5.10...7.5.11
Expand Down
4 changes: 4 additions & 0 deletions src/Framework/Constraint/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ protected function matches($other): bool
*/
protected function getCountOf($other): ?int
{
if ($other instanceof \EmptyIterator) {
return 0;
}

if ($other instanceof Countable || \is_array($other)) {
return \count($other);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Framework/Constraint/IsEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function toString(): string
*/
protected function matches($other): bool
{
if ($other instanceof \EmptyIterator) {
return true;
}

if ($other instanceof Countable) {
return \count($other) === 0;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/Framework/Constraint/CountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,14 @@ public function testCountTraversable(): void
$this->assertNotInstanceOf(\IteratorAggregate::class, $datePeriod);
$this->assertTrue($countConstraint->evaluate($datePeriod, '', true));
}

/**
* @ticket https://github.com/sebastianbergmann/phpunit/issues/3743
*/
public function test_EmptyIterator_is_handled_correctly(): void
{
$constraint = new Count(0);

$this->assertTrue($constraint->evaluate(new \EmptyIterator, '', true));
}
}
10 changes: 10 additions & 0 deletions tests/unit/Framework/Constraint/IsEmptyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ public function testConstraintIsEmpty2(): void

$this->fail();
}

/**
* @ticket https://github.com/sebastianbergmann/phpunit/issues/3743
*/
public function test_EmptyIterator_is_handled_correctly(): void
{
$constraint = new IsEmpty;

$this->assertTrue($constraint->evaluate(new \EmptyIterator, '', true));
}
}

0 comments on commit 9faa89f

Please sign in to comment.