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

60 lines
1.1 KiB
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;
2019-12-24 01:52:07 +01:00
final class FillTest extends TestCase
2019-12-24 01:52:07 +01:00
{
2019-12-25 00:35:14 +01:00
/**
* @dataProvider provideData
*/
public function testFill(array $expected, $value, int $start, int $num): void
{
$array = Arr\fill($value, $start, $num);
static::assertSame($expected, $array);
for ($i = $start; $i < $start + $num; ++$i) {
static::assertArrayHasKey($i, $array);
static::assertSame($value, Arr\at($array, $i));
}
}
public function provideData(): array
{
return [
[
['a', 'a', 'a'],
'a',
0,
3,
],
[
[],
'a',
0,
0,
],
[
[5 => true, 6 => true, 7 => true],
true,
5,
3,
],
[
[8 => null, 9 => null, 10 => null],
null,
8,
3,
],
];
}
2019-12-24 01:52:07 +01:00
}