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

56 lines
1.3 KiB
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\Str;
2019-12-24 01:52:07 +01:00
final class PartitionTest 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 testPartition(array $expected, array $array, callable $predicate): void
2019-12-25 00:35:14 +01:00
{
static::assertSame($expected, Arr\partition($array, $predicate));
2019-12-25 00:35:14 +01:00
}
public function provideData(): array
{
return [
[
[['bar', 'baz'], ['foo', 'qux']],
2020-08-27 16:14:37 +02:00
['foo', 'bar', 'baz', 'qux'],
static fn (string $str) => Str\starts_with($str, 'b'),
2019-12-25 00:35:14 +01:00
],
[
[['bar', 'baz'], ['foo', 'qux']],
2020-08-27 16:14:37 +02:00
['foo', 'bar', 'baz', 'qux'],
static fn (string $str) => Str\starts_with($str, 'b'),
2019-12-25 00:35:14 +01:00
],
[
[[], []],
[],
static fn ($_) => false,
2019-12-25 00:35:14 +01:00
],
[
[[], ['foo', 'bar', 'baz', 'qux']],
2020-08-27 16:14:37 +02:00
['foo', 'bar', 'baz', 'qux'],
static fn (string $str) => false,
2019-12-25 00:35:14 +01:00
],
[
[['foo', 'bar', 'baz', 'qux'], []],
2020-08-27 16:14:37 +02:00
['foo', 'bar', 'baz', 'qux'],
static fn (string $str) => true,
2019-12-25 00:35:14 +01:00
],
];
}
2019-12-24 01:52:07 +01:00
}