Browse Source

Collection::every() should return false for empty collection.

ADmad 10 years ago
parent
commit
44bb3245d4
2 changed files with 10 additions and 1 deletions
  1. 3 1
      src/Collection/CollectionTrait.php
  2. 7 0
      tests/TestCase/Collection/CollectionTest.php

+ 3 - 1
src/Collection/CollectionTrait.php

@@ -86,12 +86,14 @@ trait CollectionTrait
      */
     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;
     }
 
     /**

+ 7 - 0
tests/TestCase/Collection/CollectionTest.php

@@ -192,6 +192,13 @@ class CollectionTest extends TestCase
             ->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));
     }
 
     /**