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

35 lines
933 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\Iter;
2019-12-24 01:52:07 +01:00
class FromKeysTest extends TestCase
{
2020-08-08 06:35:34 +02:00
public function testFromKeys(): void
{
$actual = Iter\from_keys(['hello', 'world'], fn (string $_key) => false);
self::assertSame('hello', Iter\first_key($actual));
self::assertSame('world', Iter\last_key($actual));
self::assertFalse(Iter\first($actual));
self::assertFalse(Iter\last($actual));
}
public function testFromKeysWithNonArrayKeyKeys(): void
{
$actual = Iter\from_keys([
[1, 'hello'],
[2, 'world']
], fn (array $k) => $k[1]);
self::assertSame([1, 'hello'], Iter\first_key($actual));
self::assertSame([2, 'world'], Iter\last_key($actual));
self::assertSame('hello', Iter\first($actual));
self::assertSame('world', Iter\last($actual));
}
2019-12-24 01:52:07 +01:00
}