|
12 | 12 | use Zend\Hydrator\HydratorInterface;
|
13 | 13 | use Zend\Hydrator\HydratorPluginManager;
|
14 | 14 | use Zend\Hydrator\HydratorPluginManagerFactory;
|
| 15 | +use Zend\Hydrator\Reflection; |
15 | 16 | use Zend\ServiceManager\ServiceLocatorInterface;
|
16 | 17 |
|
17 | 18 | class HydratorPluginManagerFactoryTest extends TestCase
|
@@ -70,4 +71,99 @@ public function testFactoryConfiguresPluginManagerUnderServiceManagerV2()
|
70 | 71 | $hydrators = $factory->createService($container->reveal());
|
71 | 72 | $this->assertSame($hydrator, $hydrators->get('test'));
|
72 | 73 | }
|
| 74 | + |
| 75 | + public function testConfiguresHydratorServicesWhenFound() |
| 76 | + { |
| 77 | + $hydrator = $this->prophesize(HydratorInterface::class)->reveal(); |
| 78 | + $config = [ |
| 79 | + 'hydrators' => [ |
| 80 | + 'aliases' => [ |
| 81 | + 'test' => Reflection::class, |
| 82 | + ], |
| 83 | + 'factories' => [ |
| 84 | + 'test-too' => function ($container) use ($hydrator) { |
| 85 | + return $hydrator; |
| 86 | + }, |
| 87 | + ], |
| 88 | + ], |
| 89 | + ]; |
| 90 | + |
| 91 | + $container = $this->prophesize(ServiceLocatorInterface::class); |
| 92 | + $container->willImplement(ContainerInterface::class); |
| 93 | + |
| 94 | + $container->has('ServiceListener')->willReturn(false); |
| 95 | + $container->has('config')->willReturn(true); |
| 96 | + $container->get('config')->willReturn($config); |
| 97 | + |
| 98 | + $factory = new HydratorPluginManagerFactory(); |
| 99 | + $hydrators = $factory($container->reveal(), 'HydratorManager'); |
| 100 | + |
| 101 | + $this->assertInstanceOf(HydratorPluginManager::class, $hydrators); |
| 102 | + $this->assertTrue($hydrators->has('test')); |
| 103 | + $this->assertInstanceOf(Reflection::class, $hydrators->get('test')); |
| 104 | + $this->assertTrue($hydrators->has('test-too')); |
| 105 | + $this->assertSame($hydrator, $hydrators->get('test-too')); |
| 106 | + } |
| 107 | + |
| 108 | + public function testDoesNotConfigureHydratorServicesWhenServiceListenerPresent() |
| 109 | + { |
| 110 | + $hydrator = $this->prophesize(HydratorInterface::class)->reveal(); |
| 111 | + $config = [ |
| 112 | + 'hydrators' => [ |
| 113 | + 'aliases' => [ |
| 114 | + 'test' => Reflection::class, |
| 115 | + ], |
| 116 | + 'factories' => [ |
| 117 | + 'test-too' => function ($container) use ($hydrator) { |
| 118 | + return $hydrator; |
| 119 | + }, |
| 120 | + ], |
| 121 | + ], |
| 122 | + ]; |
| 123 | + |
| 124 | + $container = $this->prophesize(ServiceLocatorInterface::class); |
| 125 | + $container->willImplement(ContainerInterface::class); |
| 126 | + |
| 127 | + $container->has('ServiceListener')->willReturn(true); |
| 128 | + $container->has('config')->shouldNotBeCalled(); |
| 129 | + $container->get('config')->shouldNotBeCalled(); |
| 130 | + |
| 131 | + $factory = new HydratorPluginManagerFactory(); |
| 132 | + $hydrators = $factory($container->reveal(), 'HydratorManager'); |
| 133 | + |
| 134 | + $this->assertInstanceOf(HydratorPluginManager::class, $hydrators); |
| 135 | + $this->assertFalse($hydrators->has('test')); |
| 136 | + $this->assertFalse($hydrators->has('test-too')); |
| 137 | + } |
| 138 | + |
| 139 | + public function testDoesNotConfigureHydratorServicesWhenConfigServiceNotPresent() |
| 140 | + { |
| 141 | + $container = $this->prophesize(ServiceLocatorInterface::class); |
| 142 | + $container->willImplement(ContainerInterface::class); |
| 143 | + |
| 144 | + $container->has('ServiceListener')->willReturn(false); |
| 145 | + $container->has('config')->willReturn(false); |
| 146 | + $container->get('config')->shouldNotBeCalled(); |
| 147 | + |
| 148 | + $factory = new HydratorPluginManagerFactory(); |
| 149 | + $hydrators = $factory($container->reveal(), 'HydratorManager'); |
| 150 | + |
| 151 | + $this->assertInstanceOf(HydratorPluginManager::class, $hydrators); |
| 152 | + } |
| 153 | + |
| 154 | + public function testDoesNotConfigureHydratorServicesWhenConfigServiceDoesNotContainHydratorsConfig() |
| 155 | + { |
| 156 | + $container = $this->prophesize(ServiceLocatorInterface::class); |
| 157 | + $container->willImplement(ContainerInterface::class); |
| 158 | + |
| 159 | + $container->has('ServiceListener')->willReturn(false); |
| 160 | + $container->has('config')->willReturn(true); |
| 161 | + $container->get('config')->willReturn(['foo' => 'bar']); |
| 162 | + |
| 163 | + $factory = new HydratorPluginManagerFactory(); |
| 164 | + $hydrators = $factory($container->reveal(), 'HydratorManager'); |
| 165 | + |
| 166 | + $this->assertInstanceOf(HydratorPluginManager::class, $hydrators); |
| 167 | + $this->assertFalse($hydrators->has('foo')); |
| 168 | + } |
73 | 169 | }
|
0 commit comments