-
-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper to get last element of array
- Loading branch information
Showing
6 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
use Pest\Support\Arr; | ||
|
||
describe('last', function () { | ||
it('should return false for an empty arary', function () { | ||
expect(Arr::last([]))->toBeFalse(); | ||
}); | ||
|
||
it('should return the last element for an array with a single element', function () { | ||
expect(Arr::last([1]))->toBe(1); | ||
}); | ||
|
||
it('should return the last element for an array without changing the internal pointer', function () { | ||
$array = [1, 2, 3]; | ||
|
||
expect(Arr::last($array))->toBe(3); | ||
expect(current($array))->toBe(1); | ||
|
||
next($array); | ||
expect(current($array))->toBe(2); | ||
expect(Arr::last($array))->toBe(3); | ||
expect(current($array))->toBe(2); | ||
}); | ||
|
||
it('should return the last element for an associative array without changing the internal pointer', function () { | ||
$array = ['first' => 1, 'second' => 2, 'third' => 3]; | ||
|
||
expect(Arr::last($array))->toBe(3); | ||
expect(current($array))->toBe(1); | ||
|
||
next($array); | ||
expect(current($array))->toBe(2); | ||
expect(Arr::last($array))->toBe(3); | ||
expect(current($array))->toBe(2); | ||
}); | ||
|
||
it('should return the last element for an mixed key array without changing the internal pointer', function () { | ||
$array = ['first' => 1, 2, 'third' => 3]; | ||
|
||
expect(Arr::last($array))->toBe(3); | ||
expect(current($array))->toBe(1); | ||
|
||
next($array); | ||
expect(current($array))->toBe(2); | ||
expect(Arr::last($array))->toBe(3); | ||
expect(current($array))->toBe(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters