From 44bb3245d486371ed1360d95c24fefe765fce3c7 Mon Sep 17 00:00:00 2001 From: ADmad Date: Mon, 18 Apr 2016 17:32:38 +0530 Subject: [PATCH] Collection::every() should return false for empty collection. --- src/Collection/CollectionTrait.php | 4 +++- tests/TestCase/Collection/CollectionTest.php | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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)); } /**