| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace AlexLcDee\RegistryContainer\Tests;
- use AlexLcDee\RegistryContainer\Builder;
- use AlexLcDee\RegistryContainer\Exceptions\InvalidArgumentException;
- use AlexLcDee\RegistryContainer\Interfaces\RegistryContainerInterface;
- use AlexLcDee\RegistryContainer\Tests\Mocks\Registry as MockRegistry;
- use PHPUnit\Framework\TestCase;
- class BuilderTest extends TestCase
- {
- /**
- * @var Builder
- */
- private $builder;
- public function setUp()
- {
- $this->builder = Builder::create();
- }
- public function test_create()
- {
- $this->assertInstanceOf(Builder::class, $this->builder);
- }
- public function test_build()
- {
- $this->assertInstanceOf(RegistryContainerInterface::class, $this->builder->build());
- }
- public function test_withRegistryClass()
- {
- $registry = $this->builder->withRegistryClass(MockRegistry::class)->build();
- $this->assertInstanceOf(MockRegistry::class, $registry);
- }
- public function test_withRegistryClass_throws_InvalidArgumentException()
- {
- $this->expectException(InvalidArgumentException::class);
- $this->builder->withRegistryClass(\stdClass::class);
- }
- public function test_withRegistryClass_returns_cloned()
- {
- $this->assertNotSame($this->builder, $this->builder->withRegistryClass(MockRegistry::class));
- }
- public function test_withTypesMap()
- {
- /** @var MockRegistry $registry */
- $registry = $this->builder
- ->withRegistryClass(MockRegistry::class)
- ->withTypesMap(['test' => 'test'])
- ->build();
- $this->assertArrayHasKey('test', $registry->getTypesMap());
- }
- public function test_withTypesMap_rewrites_map()
- {
- /** @var MockRegistry $registry */
- $registry = $this->builder
- ->withRegistryClass(MockRegistry::class)
- ->withTypesMap(['test' => 'test'])
- ->withTypesMap(['test2' => 'test2'])
- ->build();
- $this->assertArrayHasKey('test2', $registry->getTypesMap());
- $this->assertArrayNotHasKey('test', $registry->getTypesMap());
- }
- public function test_withTypesMap_merges_maps()
- {
- /** @var MockRegistry $registry */
- $registry = $this->builder
- ->withRegistryClass(MockRegistry::class)
- ->withTypesMap(['test' => 'test'])
- ->withTypesMap(['test2' => 'test2'], true)
- ->build();
- $this->assertArrayHasKey('test', $registry->getTypesMap());
- $this->assertArrayHasKey('test2', $registry->getTypesMap());
- }
- public function test_withTypesMap_returns_cloned()
- {
- $this->assertNotSame($this->builder, $this->builder->withTypesMap(['test2' => 'test2']));
- }
- }
|