endtoend-test-psl/tests/Psl/Arr/LastxTest.php

45 lines
860 B
PHP
Raw Normal View History

2019-12-24 01:52:07 +01:00
<?php
declare(strict_types=1);
namespace Psl\Tests\Arr;
use PHPUnit\Framework\TestCase;
2019-12-25 00:35:14 +01:00
use Psl\Arr;
use Psl\Exception;
use Psl\Iter;
2019-12-24 01:52:07 +01:00
final class LastxTest extends TestCase
2019-12-24 01:52:07 +01:00
{
2019-12-25 00:35:14 +01:00
/**
* @dataProvider provideData
*/
public function testLastx($expected, array $array): void
{
static::assertSame($expected, Arr\lastx($array));
}
public function provideData(): array
{
return [
[
10,
Iter\to_array(Iter\range(0, 10)),
],
[
null,
[null],
],
];
}
public function testLastxThrowsForEmptyArray(): void
{
$this->expectException(Exception\InvariantViolationException::class);
$this->expectExceptionMessage('Expected a non-empty array.');
Arr\lastx([]);
}
2019-12-24 01:52:07 +01:00
}