diff --git a/ChangeLog-7.5.md b/ChangeLog-7.5.md index 738cfdb505d..bb4fee75cc6 100644 --- a/ChangeLog-7.5.md +++ b/ChangeLog-7.5.md @@ -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 @@ -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 diff --git a/src/Framework/Constraint/Count.php b/src/Framework/Constraint/Count.php index 742fdbc3622..857dddd5958 100644 --- a/src/Framework/Constraint/Count.php +++ b/src/Framework/Constraint/Count.php @@ -49,6 +49,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); } diff --git a/src/Framework/Constraint/IsEmpty.php b/src/Framework/Constraint/IsEmpty.php index d4274386b49..26db5b456f5 100644 --- a/src/Framework/Constraint/IsEmpty.php +++ b/src/Framework/Constraint/IsEmpty.php @@ -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; } diff --git a/tests/unit/Framework/Constraint/CountTest.php b/tests/unit/Framework/Constraint/CountTest.php index eac8a990a38..acd8fdb7b7c 100644 --- a/tests/unit/Framework/Constraint/CountTest.php +++ b/tests/unit/Framework/Constraint/CountTest.php @@ -173,4 +173,14 @@ public function testCountEvaluateReturnsNullWithNonCountableAndNonTraversableOth ); } } + + /** + * @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)); + } } diff --git a/tests/unit/Framework/Constraint/IsEmptyTest.php b/tests/unit/Framework/Constraint/IsEmptyTest.php index d69569448b2..0b38b3c30ec 100644 --- a/tests/unit/Framework/Constraint/IsEmptyTest.php +++ b/tests/unit/Framework/Constraint/IsEmptyTest.php @@ -67,4 +67,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)); + } }