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

40 lines
1010 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
2019-12-25 00:35:14 +01:00
/**
* @covers \Psl\Arr\contains
*/
2019-12-24 01:52:07 +01:00
class ContainsTest extends TestCase
{
2019-12-25 00:35:14 +01:00
/**
* @dataProvider provideData
*/
public function testContains(bool $expected, iterable $iterable, $value): void
{
static::assertSame($expected, Arr\contains($iterable, $value));
}
public function provideData(): array
{
return [
[true, [1, 2], 1],
[true, new Collection\Vector([1, 2, 3, 4]), 4],
[false, new Collection\Vector([1, 2, 3, 4]), 5],
[true, new Collection\Map(['a' => 'b']), 'b'],
[true, new Collection\Pair('a', 'b'), 'a'],
[true, new Collection\Pair('a', 'b'), 'b'],
[false, new Collection\Pair('a', 'b'), 'c'],
[true, (fn () => yield 'a')(), 'a'],
[false, (fn () => yield 'a')(), 'b'],
[false, ['0'], 0],
];
}
2019-12-24 01:52:07 +01:00
}