diff --git a/src/Collection/CollectionTrait.php b/src/Collection/CollectionTrait.php index a885a0d2b09..a37458575d6 100644 --- a/src/Collection/CollectionTrait.php +++ b/src/Collection/CollectionTrait.php @@ -86,12 +86,14 @@ public function reject(callable $c) */ public function every(callable $c) { + $return = false; foreach ($this->unwrap() as $key => $value) { + $return = true; if (!$c($value, $key)) { return false; } } - return true; + return $return; } /** diff --git a/tests/TestCase/Collection/CollectionTest.php b/tests/TestCase/Collection/CollectionTest.php index 0183b7c2d4b..f82a078017f 100644 --- a/tests/TestCase/Collection/CollectionTest.php +++ b/tests/TestCase/Collection/CollectionTest.php @@ -192,6 +192,13 @@ public function testEveryReturnFalse() ->will($this->returnValue(false)); $callable->expects($this->exactly(2))->method('__invoke'); $this->assertFalse($collection->every($callable)); + + $items = []; + $collection = new Collection($items); + $callable = $this->getMock('stdClass', ['__invoke']); + $callable->expects($this->never()) + ->method('__invoke'); + $this->assertFalse($collection->every($callable)); } /**