2020-09-03 00:06:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Arr;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Psl\Arr;
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
final class MapTest extends TestCase
|
2020-09-03 00:06:20 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testMap(array $expected, array $array, callable $function): void
|
|
|
|
{
|
|
|
|
$result = Arr\map($array, $function);
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame($expected, $result);
|
2020-09-03 00:06:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): iterable
|
|
|
|
{
|
2020-10-15 10:18:03 +02:00
|
|
|
yield [[1, 2, 3], [1, 2, 3], static fn (int $v): int => $v];
|
|
|
|
yield [[2, 4, 6], [1, 2, 3], static fn (int $v): int => $v * 2];
|
|
|
|
yield [['1', '2', '3'], [1, 2, 3], static fn (int $v): string => (string)$v];
|
|
|
|
yield [[], [], static fn (int $k): string => (string)$v];
|
2020-09-03 00:06:20 +02:00
|
|
|
}
|
|
|
|
}
|