mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-12-12 09:09:45 +01:00
48 lines
1.3 KiB
PHP
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;
|
|
|
|
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
|
|
{
|
|
self::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, (fn () => yield 'foo' => 'bar')(), 'foo'];
|
|
yield [true, (fn () => yield 'foo' => 'bar')(), 'bar'];
|
|
}
|
|
}
|