mirror of
https://github.com/danog/Valinor.git
synced 2024-11-30 04:39:05 +01:00
ae7ddcf3ca
Using two instances of the same class implementing the `__invoke()` method in one of the mapper builder methods will now be properly handled by the library
38 lines
1.0 KiB
PHP
38 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace CuyZ\Valinor\Tests\Unit\Definition;
|
|
|
|
use CuyZ\Valinor\Definition\FunctionsContainer;
|
|
use CuyZ\Valinor\Tests\Fake\Definition\Repository\FakeFunctionDefinitionRepository;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use function iterator_to_array;
|
|
|
|
final class FunctionsContainerTest extends TestCase
|
|
{
|
|
public function test_keys_are_kept_when_iterating(): void
|
|
{
|
|
$functions = (new FunctionsContainer(new FakeFunctionDefinitionRepository(), [
|
|
'foo' => fn () => 'foo',
|
|
'bar' => fn () => 'bar',
|
|
]));
|
|
|
|
$functions = iterator_to_array($functions);
|
|
|
|
self::assertArrayHasKey('foo', $functions);
|
|
self::assertArrayHasKey('bar', $functions);
|
|
}
|
|
|
|
public function test_function_object_remains_the_same(): void
|
|
{
|
|
$functions = (new FunctionsContainer(new FakeFunctionDefinitionRepository(), [fn () => 'foo']));
|
|
|
|
$functionA = $functions->get(0);
|
|
$functionB = $functions->get(0);
|
|
|
|
self::assertSame($functionA, $functionB);
|
|
}
|
|
}
|