Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Collection::every() should return false for empty collection.
  • Loading branch information
ADmad committed Apr 18, 2016
1 parent e59889f commit 44bb324
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Collection/CollectionTrait.php
Expand Up @@ -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;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/TestCase/Collection/CollectionTest.php
Expand Up @@ -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));
}

/**
Expand Down

0 comments on commit 44bb324

Please sign in to comment.