|
9 | 9 |
|
10 | 10 | use Interop\Container\ContainerInterface;
|
11 | 11 | use PHPUnit_Framework_TestCase as TestCase;
|
| 12 | +use Zend\Filter\Boolean; |
| 13 | +use Zend\Filter\FilterInterface; |
12 | 14 | use Zend\Filter\FilterPluginManager;
|
13 | 15 | use Zend\Filter\FilterPluginManagerFactory;
|
14 | 16 | use Zend\ServiceManager\ServiceLocatorInterface;
|
@@ -73,4 +75,99 @@ public function testFactoryConfiguresPluginManagerUnderServiceManagerV2()
|
73 | 75 | $filters = $factory->createService($container->reveal());
|
74 | 76 | $this->assertSame($filter, $filters->get('test'));
|
75 | 77 | }
|
| 78 | + |
| 79 | + public function testConfiguresFilterServicesWhenFound() |
| 80 | + { |
| 81 | + $filter = $this->prophesize(FilterInterface::class)->reveal(); |
| 82 | + $config = [ |
| 83 | + 'filters' => [ |
| 84 | + 'aliases' => [ |
| 85 | + 'test' => Boolean::class, |
| 86 | + ], |
| 87 | + 'factories' => [ |
| 88 | + 'test-too' => function ($container) use ($filter) { |
| 89 | + return $filter; |
| 90 | + }, |
| 91 | + ], |
| 92 | + ], |
| 93 | + ]; |
| 94 | + |
| 95 | + $container = $this->prophesize(ServiceLocatorInterface::class); |
| 96 | + $container->willImplement(ContainerInterface::class); |
| 97 | + |
| 98 | + $container->has('ServiceListener')->willReturn(false); |
| 99 | + $container->has('config')->willReturn(true); |
| 100 | + $container->get('config')->willReturn($config); |
| 101 | + |
| 102 | + $factory = new FilterPluginManagerFactory(); |
| 103 | + $filters = $factory($container->reveal(), 'FilterManager'); |
| 104 | + |
| 105 | + $this->assertInstanceOf(FilterPluginManager::class, $filters); |
| 106 | + $this->assertTrue($filters->has('test')); |
| 107 | + $this->assertInstanceOf(Boolean::class, $filters->get('test')); |
| 108 | + $this->assertTrue($filters->has('test-too')); |
| 109 | + $this->assertSame($filter, $filters->get('test-too')); |
| 110 | + } |
| 111 | + |
| 112 | + public function testDoesNotConfigureFilterServicesWhenServiceListenerPresent() |
| 113 | + { |
| 114 | + $filter = $this->prophesize(FilterInterface::class)->reveal(); |
| 115 | + $config = [ |
| 116 | + 'filters' => [ |
| 117 | + 'aliases' => [ |
| 118 | + 'test' => Boolean::class, |
| 119 | + ], |
| 120 | + 'factories' => [ |
| 121 | + 'test-too' => function ($container) use ($filter) { |
| 122 | + return $filter; |
| 123 | + }, |
| 124 | + ], |
| 125 | + ], |
| 126 | + ]; |
| 127 | + |
| 128 | + $container = $this->prophesize(ServiceLocatorInterface::class); |
| 129 | + $container->willImplement(ContainerInterface::class); |
| 130 | + |
| 131 | + $container->has('ServiceListener')->willReturn(true); |
| 132 | + $container->has('config')->shouldNotBeCalled(); |
| 133 | + $container->get('config')->shouldNotBeCalled(); |
| 134 | + |
| 135 | + $factory = new FilterPluginManagerFactory(); |
| 136 | + $filters = $factory($container->reveal(), 'FilterManager'); |
| 137 | + |
| 138 | + $this->assertInstanceOf(FilterPluginManager::class, $filters); |
| 139 | + $this->assertFalse($filters->has('test')); |
| 140 | + $this->assertFalse($filters->has('test-too')); |
| 141 | + } |
| 142 | + |
| 143 | + public function testDoesNotConfigureFilterServicesWhenConfigServiceNotPresent() |
| 144 | + { |
| 145 | + $container = $this->prophesize(ServiceLocatorInterface::class); |
| 146 | + $container->willImplement(ContainerInterface::class); |
| 147 | + |
| 148 | + $container->has('ServiceListener')->willReturn(false); |
| 149 | + $container->has('config')->willReturn(false); |
| 150 | + $container->get('config')->shouldNotBeCalled(); |
| 151 | + |
| 152 | + $factory = new FilterPluginManagerFactory(); |
| 153 | + $filters = $factory($container->reveal(), 'FilterManager'); |
| 154 | + |
| 155 | + $this->assertInstanceOf(FilterPluginManager::class, $filters); |
| 156 | + } |
| 157 | + |
| 158 | + public function testDoesNotConfigureFilterServicesWhenConfigServiceDoesNotContainFiltersConfig() |
| 159 | + { |
| 160 | + $container = $this->prophesize(ServiceLocatorInterface::class); |
| 161 | + $container->willImplement(ContainerInterface::class); |
| 162 | + |
| 163 | + $container->has('ServiceListener')->willReturn(false); |
| 164 | + $container->has('config')->willReturn(true); |
| 165 | + $container->get('config')->willReturn(['foo' => 'bar']); |
| 166 | + |
| 167 | + $factory = new FilterPluginManagerFactory(); |
| 168 | + $filters = $factory($container->reveal(), 'FilterManager'); |
| 169 | + |
| 170 | + $this->assertInstanceOf(FilterPluginManager::class, $filters); |
| 171 | + $this->assertFalse($filters->has('foo')); |
| 172 | + } |
76 | 173 | }
|
0 commit comments