endtoend-test-psl/tests/Psl/Iter/ContainsTest.php
2020-10-15 11:05:30 +02:00

48 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Psl\Tests\Iter;
use PHPUnit\Framework\TestCase;
use Psl\Collection;
use Psl\Iter;
final class ContainsTest extends TestCase
{
/**
* @psalm-template T
*
* @psalm-param iterable<T> $iterable
* @psalm-param T $value
*
* @dataProvider provideData
*/
public function testContainsKey(bool $expected, iterable $iterable, $value): void
{
static::assertSame($expected, Iter\contains($iterable, $value));
}
public function provideData(): iterable
{
yield [false, [], 0];
yield [false, [], 1];
yield [false, [], null];
yield [false, [0], null];
yield [true, [null], null];
yield [false, [1, 2], 0];
yield [true, [1, 2], 1];
yield [true, [1, 2], 2];
yield [false, ['hello' => 'world'], 'hello'];
yield [true, ['hello' => 'world'], 'world'];
yield [false, ['hello' => 'world'], 'worlD'];
yield [true, [null => null], null];
yield [false, new Collection\Vector([1, 2]), 0];
yield [true, new Collection\Vector([1, 2]), 1];
yield [true, new Collection\Vector([1, 2]), 2];
yield [false, (static fn () => yield 'foo' => 'bar')(), 'foo'];
yield [true, (static fn () => yield 'foo' => 'bar')(), 'bar'];
}
}