endtoend-test-psl/tests/Psl/Iter/FirstKeyTest.php

41 lines
941 B
PHP
Raw Normal View History

2019-12-24 01:52:07 +01:00
<?php
declare(strict_types=1);
namespace Psl\Tests\Iter;
use PHPUnit\Framework\TestCase;
2020-08-08 06:35:34 +02:00
use Psl\Collection;
use Psl\Iter;
2019-12-24 01:52:07 +01:00
class FirstKeyTest extends TestCase
{
2020-08-08 06:35:34 +02:00
/**
* @dataProvider provideData
*/
public function testFirstKey($expected, iterable $iterable): void
{
$result = Iter\first_key($iterable);
self::assertSame($expected, $result);
}
public function provideData(): iterable
{
yield [null, []];
yield [null, new \SplDoublyLinkedList()];
yield ['a', ['a' => 'b']];
yield [0, ['a', 'b']];
yield [0, new Collection\Vector(['a', 'b'])];
yield [0, new Collection\Vector(['a' => 'b'])];
yield ['a', new Collection\Map(['a' => 'b'])];
yield [null, (static function () {
yield null => null;
})()];
yield [null, (static function () {
return;
yield;
})()];
}
2019-12-24 01:52:07 +01:00
}