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

42 lines
961 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;
use Psl\Collection;
2019-12-24 01:52:07 +01:00
class MergeTest extends TestCase
{
2019-12-25 00:35:14 +01:00
/**
* @dataProvider provideData
*/
public function testMerge(array $expected, iterable $iterable, iterable ...$iterables): void
{
self::assertSame($expected, Arr\merge($iterable, ...$iterables));
}
public function provideData(): array
{
return [
[
['a' => 'b', 'b' => 'c', 'c' => 'd', 'd' => 'e'],
new Collection\Map(['a' => 'foo', 'b' => 'bar']),
['a' => 'b'],
2020-02-21 02:03:40 +01:00
new Collection\MutableMap(['b' => 'c', 'c' => 'd']),
2019-12-25 00:35:14 +01:00
(fn () => yield 'd' => 'baz')(),
(fn () => yield 'd' => 'e')(),
],
[
[1, 2, 9, 8],
[0 => 1, 1 => 2],
[2 => 9, 3 => 8],
],
];
}
2019-12-24 01:52:07 +01:00
}