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

39 lines
803 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;
2019-12-24 01:52:07 +01:00
final class AtTest extends TestCase
2019-12-24 01:52:07 +01:00
{
2019-12-25 00:35:14 +01:00
/**
* @dataProvider provideData
*/
public function testAt($expected, array $array, $key): void
{
static::assertSame($expected, Arr\at($array, $key));
}
public function provideData(): array
{
return [
[5, ['a' => 4, 'b' => 5], 'b'],
[0, [0, 1], 0],
[1, [1, 2], 0],
[null, [null], 0],
];
}
public function testAtThrowsForOutOfBoundKey(): void
{
$this->expectException(Exception\InvariantViolationException::class);
2020-07-09 00:28:29 +02:00
$this->expectExceptionMessage('Key (5) is out-of-bounds.');
2019-12-25 00:35:14 +01:00
Arr\at([], 5);
}
2019-12-24 01:52:07 +01:00
}