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
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
final class FromEntriesTest extends TestCase
|
2019-12-24 01:52:07 +01:00
|
|
|
{
|
2020-08-08 06:35:34 +02:00
|
|
|
public function testEmptyEntries(): void
|
|
|
|
{
|
|
|
|
$actual = Iter\from_entries([]);
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertCount(0, $actual);
|
2020-08-08 06:35:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFromEntries(): void
|
|
|
|
{
|
|
|
|
$actual = Iter\from_entries([
|
|
|
|
[1, 'hello'],
|
|
|
|
[2, 'world']
|
|
|
|
]);
|
|
|
|
|
|
|
|
$array = Iter\to_array_with_keys($actual);
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertCount(2, $array);
|
|
|
|
static::assertSame('hello', $array[1]);
|
|
|
|
static::assertSame('world', $array[2]);
|
2020-08-08 06:35:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFromEntriesWithNonArrayKeyKeys(): void
|
|
|
|
{
|
|
|
|
$actual = Iter\from_entries([
|
|
|
|
[['1', '2'], 'hello'],
|
|
|
|
[['3', '4'], 'world']
|
|
|
|
]);
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame('hello', Iter\first($actual));
|
|
|
|
static::assertSame('world', Iter\last($actual));
|
2020-08-08 06:35:34 +02:00
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame(['1', '2'], Iter\first_key($actual));
|
|
|
|
static::assertSame(['3', '4'], Iter\last_key($actual));
|
2020-08-08 06:35:34 +02:00
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|