mirror of
https://github.com/pestphp/pest.git
synced 2026-12-04 06:55:05 +01:00
d314fc0540
Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Pest\Support\Arr;
|
|
|
|
describe('last', function (): void {
|
|
it('should return false for an empty arary', function (): void {
|
|
expect(Arr::last([]))->toBeFalse();
|
|
});
|
|
|
|
it('should return the last element for an array with a single element', function (): void {
|
|
expect(Arr::last([1]))->toBe(1);
|
|
});
|
|
|
|
it('should return the last element for an array without changing the internal pointer', function (): void {
|
|
$array = [1, 2, 3];
|
|
|
|
expect(Arr::last($array))->toBe(3)
|
|
->and(current($array))->toBe(1);
|
|
|
|
next($array);
|
|
expect(current($array))->toBe(2)
|
|
->and(Arr::last($array))->toBe(3)
|
|
->and(current($array))->toBe(2);
|
|
});
|
|
|
|
it('should return the last element for an associative array without changing the internal pointer', function (): void {
|
|
$array = ['first' => 1, 'second' => 2, 'third' => 3];
|
|
|
|
expect(Arr::last($array))->toBe(3)
|
|
->and(current($array))->toBe(1);
|
|
|
|
next($array);
|
|
expect(current($array))->toBe(2)
|
|
->and(Arr::last($array))->toBe(3)
|
|
->and(current($array))->toBe(2);
|
|
});
|
|
|
|
it('should return the last element for an mixed key array without changing the internal pointer', function (): void {
|
|
$array = ['first' => 1, 2, 'third' => 3];
|
|
|
|
expect(Arr::last($array))->toBe(3)
|
|
->and(current($array))->toBe(1);
|
|
|
|
next($array);
|
|
expect(current($array))->toBe(2)
|
|
->and(Arr::last($array))->toBe(3)
|
|
->and(current($array))->toBe(2);
|
|
});
|
|
});
|
|
|
|
describe('stringKeys', function (): void {
|
|
it('returns every key as a string', function (): void {
|
|
expect(Arr::stringKeys(['123' => true, 'app/Service.php' => true]))->toBe(['123', 'app/Service.php']);
|
|
});
|
|
});
|