|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * This file is part of the asm/phpflo-bundle package. |
| 4 | + * |
| 5 | + * (c) Marc Aschmann <[email protected]> |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + */ |
| 10 | + |
| 11 | +namespace Tests\Flow; |
| 12 | + |
| 13 | + |
| 14 | +use Asm\PhpFloBundle\Flow\ComponentRegistry; |
| 15 | +use PhpFlo\ComponentInterface; |
| 16 | + |
| 17 | +/** |
| 18 | + * Class ComponentRegistryTest |
| 19 | + * |
| 20 | + * @package Tests\Flow |
| 21 | + * @author Marc Aschmann <[email protected]> |
| 22 | + */ |
| 23 | +class ComponentRegistryTest extends \PHPUnit_Framework_TestCase |
| 24 | +{ |
| 25 | + public function testGetReference() |
| 26 | + { |
| 27 | + $componentMock = $this->createMock('\PhpFlo\ComponentInterface'); |
| 28 | + $registry = $this->createRegistry(); |
| 29 | + $registry->addReference($componentMock, 'component_1'); |
| 30 | + |
| 31 | + $component = $registry->getReference('component_1'); |
| 32 | + $this->assertInstanceOf('\PhpFlo\ComponentInterface', $component, 'addReference failed'); |
| 33 | + } |
| 34 | + |
| 35 | + public function testGetReferences() |
| 36 | + { |
| 37 | + $componentMock = $this->createMock('\PhpFlo\ComponentInterface'); |
| 38 | + $registry = $this->createRegistry(); |
| 39 | + $registry |
| 40 | + ->addReference($componentMock, 'component_1') |
| 41 | + ->addReference($componentMock, 'component_2'); |
| 42 | + |
| 43 | + $references = $registry->getReferences(); |
| 44 | + |
| 45 | + $this->assertTrue(is_array($references)); |
| 46 | + $this->assertArrayHasKey('component_1', $references, 'registry key for component_1 not found'); |
| 47 | + $this->assertArrayHasKey('component_2', $references, 'registry key for component_2 not found'); |
| 48 | + } |
| 49 | + |
| 50 | + public function testRemoveReference() |
| 51 | + { |
| 52 | + $componentMock = $this->createMock('\PhpFlo\ComponentInterface'); |
| 53 | + $registry = $this->createRegistry(); |
| 54 | + $registry->addReference($componentMock, 'component_1'); |
| 55 | + $component = $registry->getReference('component_1'); |
| 56 | + $this->assertInstanceOf('\PhpFlo\ComponentInterface', $component, 'addReference failed'); |
| 57 | + $registry->removeReference('component_1'); |
| 58 | + $result = $registry->getReference('component_1'); |
| 59 | + $this->assertFalse($result, 'reference was not removed'); |
| 60 | + } |
| 61 | + |
| 62 | + private function createRegistry() |
| 63 | + { |
| 64 | + return new ComponentRegistry(); |
| 65 | + } |
| 66 | +} |
0 commit comments