Skip to content

Commit

Permalink
[9.x] Improve test for Last method in Collection (#43351)
Browse files Browse the repository at this point in the history
  • Loading branch information
moharami authored Jul 21, 2022
1 parent 3598e71 commit d19ed47
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ public function testLastReturnsLastItemInCollection($collection)
{
$c = new $collection(['foo', 'bar']);
$this->assertSame('bar', $c->last());

$c = new $collection([]);
$this->assertNull($c->last());
}

/**
Expand All @@ -310,10 +313,16 @@ public function testLastWithCallback($collection)
return $value < 250;
});
$this->assertEquals(200, $result);

$result = $data->last(function ($value, $key) {
return $key < 2;
});
$this->assertEquals(200, $result);

$result = $data->last(function ($value) {
return $value > 300;
});
$this->assertNull($result);
}

/**
Expand All @@ -326,6 +335,12 @@ public function testLastWithCallbackAndDefault($collection)
return $value === 'baz';
}, 'default');
$this->assertSame('default', $result);

$data = new $collection(['foo', 'bar', 'Bar']);
$result = $data->last(function ($value) {
return $value === 'bar';
}, 'default');
$this->assertSame('bar', $result);
}

/**
Expand Down

0 comments on commit d19ed47

Please sign in to comment.