Skip to content

Commit

Permalink
Merge pull request #16532 from vlakoff/collection-test
Browse files Browse the repository at this point in the history
[5.3] Consolidate tests for first() and last() Collection methods
  • Loading branch information
taylorotwell authored Nov 24, 2016
2 parents 1cebd25 + 38c94b7 commit 42767b2
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,34 @@ public function testFirstReturnsFirstItemInCollection()
$this->assertEquals('foo', $c->first());
}

public function testFirstWithCallback()
{
$data = new Collection(['foo', 'bar', 'baz']);
$result = $data->first(function ($value) {
return $value === 'bar';
});
$this->assertEquals('bar', $result);
}

public function testFirstWithCallbackAndDefault()
{
$data = new Collection(['foo', 'bar']);
$result = $data->first(function ($value) {
return $value === 'baz';
}, 'default');
$this->assertEquals('default', $result);
}

public function testFirstWithDefaultAndWithoutCallback()
{
$data = new Collection;
$result = $data->first(null, 'default');
$this->assertEquals('default', $result);
}

public function testLastReturnsLastItemInCollection()
{
$c = new Collection(['foo', 'bar']);

$this->assertEquals('bar', $c->last());
}

Expand Down Expand Up @@ -957,31 +981,6 @@ public function testTransform()
$this->assertEquals(['first' => 'first-rolyat', 'last' => 'last-llewto'], $data->all());
}

public function testFirstWithCallback()
{
$data = new Collection(['foo', 'bar', 'baz']);
$result = $data->first(function ($value) {
return $value === 'bar';
});
$this->assertEquals('bar', $result);
}

public function testFirstWithCallbackAndDefault()
{
$data = new Collection(['foo', 'bar']);
$result = $data->first(function ($value) {
return $value === 'baz';
}, 'default');
$this->assertEquals('default', $result);
}

public function testFirstWithDefaultAndWithoutCallback()
{
$data = new Collection;
$result = $data->first(null, 'default');
$this->assertEquals('default', $result);
}

public function testGroupByAttribute()
{
$data = new Collection([['rating' => 1, 'url' => '1'], ['rating' => 1, 'url' => '1'], ['rating' => 2, 'url' => '2']]);
Expand Down

0 comments on commit 42767b2

Please sign in to comment.