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

41 lines
866 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;
2019-12-24 01:52:07 +01:00
final class SortWithKeysTest extends TestCase
2019-12-24 01:52:07 +01:00
{
2019-12-25 00:35:14 +01:00
/**
* @dataProvider provideData
*/
2020-08-27 16:14:37 +02:00
public function testSort(array $expected, array $array, ?callable $comparator = null): void
2019-12-25 00:35:14 +01:00
{
2020-08-27 16:14:37 +02:00
static::assertSame($expected, Arr\sort_with_keys($array, $comparator));
2019-12-25 00:35:14 +01:00
}
public function provideData(): array
{
return [
[
[1 => 'a', 2 => 'b', 0 => 'c'],
2020-08-27 16:14:37 +02:00
['c', 'a', 'b'],
2019-12-25 00:35:14 +01:00
],
[
[8, 9, 10],
2020-08-27 16:14:37 +02:00
[8, 9, 10],
static fn (int $a, int $b) => $a <=> $b ? -1 : 1,
2019-12-25 00:35:14 +01:00
],
[
['foo' => 'bar', 'bar' => 'baz'],
['foo' => 'bar', 'bar' => 'baz'],
],
];
}
2019-12-24 01:52:07 +01:00
}