mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-12-02 17:56:09 +01:00
38 lines
854 B
PHP
38 lines
854 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Psl\Tests\Arr;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psl\Arr;
|
|
use Psl\Str;
|
|
|
|
class UniqueByTest extends TestCase
|
|
{
|
|
/**
|
|
* @dataProvider provideData
|
|
*/
|
|
public function testUniqueBy(array $expected, iterable $iterable, callable $scalar_fun): void
|
|
{
|
|
static::assertSame($expected, Arr\unique_by($iterable, $scalar_fun));
|
|
}
|
|
|
|
public function provideData(): array
|
|
{
|
|
return [
|
|
[
|
|
[0 => 'a', 4 => 'saif'],
|
|
['a', 'b', 'c', 'd', 'saif', 'jack'],
|
|
fn ($value) => Str\length($value),
|
|
],
|
|
|
|
[
|
|
[0 => 'foo', 2 => 'bar', 4 => '@baz'],
|
|
['foo', '@foo', 'bar', '@bar', '@baz'],
|
|
fn ($value) => Str\replace($value, '@', ''),
|
|
],
|
|
];
|
|
}
|
|
}
|