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
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
final class FlipTest extends TestCase
|
2019-12-24 01:52:07 +01:00
|
|
|
{
|
2019-12-25 00:35:14 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testFlip(array $expected, $actual): void
|
|
|
|
{
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame($expected, Arr\flip($actual));
|
2019-12-25 00:35:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
['a' => 'b', 'b' => 'c', 'c' => 'd'],
|
|
|
|
['b' => 'a', 'c' => 'b', 'd' => 'c'],
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
[1 => 0, 2 => 1, 3 => 2, 4 => 3, 5 => 4, 6 => 5, 7 => 6, 8 => 7, 9 => 8, 10 => 9],
|
|
|
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2020-07-06 20:23:26 +02:00
|
|
|
|
|
|
|
public function testFlipThrowsForNonArrayKeyValues(): void
|
|
|
|
{
|
|
|
|
$this->expectException(Exception\InvariantViolationException::class);
|
2020-09-05 17:23:37 +02:00
|
|
|
$this->expectExceptionMessage(
|
|
|
|
'Expected all values to be of type array-key, value of type (resource) provided.'
|
|
|
|
);
|
2020-07-06 20:23:26 +02:00
|
|
|
|
|
|
|
Arr\flip([STDOUT]);
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|