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
|
|
|
|
|
|
|
class FlipTest extends TestCase
|
|
|
|
{
|
2019-12-25 00:35:14 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
|
|
|
public function testFlip(array $expected, $actual): void
|
|
|
|
{
|
|
|
|
self::assertSame($expected, Arr\flip($actual));
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
$this->expectExceptionMessage('Expected all values to be of type array-key, value of type (resource) provided.');
|
|
|
|
|
|
|
|
Arr\flip([STDOUT]);
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|