|
10 | 10 | namespace ZendTest\Mvc\Service;
|
11 | 11 |
|
12 | 12 | use PHPUnit_Framework_TestCase as TestCase;
|
| 13 | +use ReflectionClass; |
13 | 14 | use ReflectionProperty;
|
14 | 15 | use Zend\Mvc\Service\ServiceListenerFactory;
|
| 16 | +use Zend\ServiceManager\ServiceManager; |
15 | 17 |
|
16 | 18 | class ServiceListenerFactoryTest extends TestCase
|
17 | 19 | {
|
18 | 20 | public function setUp()
|
19 | 21 | {
|
20 |
| - $sm = $this->sm = $this->getMockBuilder('Zend\ServiceManager\ServiceManager') |
| 22 | + $sm = $this->sm = $this->getMockBuilder(ServiceManager::class) |
21 | 23 | ->setMethods(['get'])
|
22 | 24 | ->getMock();
|
23 | 25 |
|
24 | 26 | $this->factory = new ServiceListenerFactory();
|
25 | 27 | }
|
26 | 28 |
|
| 29 | + private function isServiceManagerV3() |
| 30 | + { |
| 31 | + $r = new ReflectionClass(ServiceManager::class); |
| 32 | + return $r->hasMethod('configure'); |
| 33 | + } |
| 34 | + |
27 | 35 | /**
|
28 | 36 | * @expectedException Zend\ServiceManager\Exception\ServiceNotCreatedException
|
29 | 37 | * @expectedExceptionMessage The value of service_listener_options must be an array, string given.
|
@@ -191,4 +199,78 @@ public function testDefinesExpectedAliasesForConsole()
|
191 | 199 | $this->assertArrayHasKey('console', $config['aliases'], 'Missing "console" alias from default service config');
|
192 | 200 | $this->assertArrayHasKey('Console', $config['aliases'], 'Missing "Console" alias from default service config');
|
193 | 201 | }
|
| 202 | + |
| 203 | + public function testDefinesExpectedApplicationAliasesUnderV3() |
| 204 | + { |
| 205 | + if (! $this->isServiceManagerV3()) { |
| 206 | + $this->markTestSkipped('Application aliases are only defined under zend-servicemanager v3'); |
| 207 | + } |
| 208 | + |
| 209 | + $r = new ReflectionProperty($this->factory, 'defaultServiceConfig'); |
| 210 | + $r->setAccessible(true); |
| 211 | + $config = $r->getValue($this->factory); |
| 212 | + |
| 213 | + // @codingStandardsIgnoreStart |
| 214 | + $this->assertArrayHasKey('aliases', $config, 'Missing aliases from default service config'); |
| 215 | + $this->assertArrayHasKey('application', $config['aliases'], 'Missing "application" alias from default service config'); |
| 216 | + // @codingStandardsIgnoreEnd |
| 217 | + } |
| 218 | + |
| 219 | + public function testDefinesExpectedConfigAliasesUnderV3() |
| 220 | + { |
| 221 | + if (! $this->isServiceManagerV3()) { |
| 222 | + $this->markTestSkipped('Config aliases are only defined under zend-servicemanager v3'); |
| 223 | + } |
| 224 | + |
| 225 | + $r = new ReflectionProperty($this->factory, 'defaultServiceConfig'); |
| 226 | + $r->setAccessible(true); |
| 227 | + $config = $r->getValue($this->factory); |
| 228 | + |
| 229 | + $this->assertArrayHasKey('aliases', $config, 'Missing aliases from default service config'); |
| 230 | + $this->assertArrayHasKey('Config', $config['aliases'], 'Missing "Config" alias from default service config'); |
| 231 | + } |
| 232 | + |
| 233 | + public function testDefinesExpectedRequestAliasesUnderV3() |
| 234 | + { |
| 235 | + if (! $this->isServiceManagerV3()) { |
| 236 | + $this->markTestSkipped('Request aliases are only defined under zend-servicemanager v3'); |
| 237 | + } |
| 238 | + |
| 239 | + $r = new ReflectionProperty($this->factory, 'defaultServiceConfig'); |
| 240 | + $r->setAccessible(true); |
| 241 | + $config = $r->getValue($this->factory); |
| 242 | + |
| 243 | + $this->assertArrayHasKey('aliases', $config, 'Missing aliases from default service config'); |
| 244 | + $this->assertArrayHasKey('request', $config['aliases'], 'Missing "request" alias from default service config'); |
| 245 | + } |
| 246 | + |
| 247 | + public function testDefinesExpectedResponseFactories() |
| 248 | + { |
| 249 | + if (! $this->isServiceManagerV3()) { |
| 250 | + $this->markTestSkipped('Response aliases are only defined under zend-servicemanager v3'); |
| 251 | + } |
| 252 | + |
| 253 | + $r = new ReflectionProperty($this->factory, 'defaultServiceConfig'); |
| 254 | + $r->setAccessible(true); |
| 255 | + $config = $r->getValue($this->factory); |
| 256 | + |
| 257 | + // @codingStandardsIgnoreStart |
| 258 | + $this->assertArrayHasKey('aliases', $config, 'Missing aliases from default service config'); |
| 259 | + $this->assertArrayHasKey('response', $config['aliases'], 'Missing "response" alias from default service config'); |
| 260 | + // @codingStandardsIgnoreEnd |
| 261 | + } |
| 262 | + |
| 263 | + public function testDefinesExpectedRouterAliases() |
| 264 | + { |
| 265 | + if (! $this->isServiceManagerV3()) { |
| 266 | + $this->markTestSkipped('Router aliases are only defined under zend-servicemanager v3'); |
| 267 | + } |
| 268 | + |
| 269 | + $r = new ReflectionProperty($this->factory, 'defaultServiceConfig'); |
| 270 | + $r->setAccessible(true); |
| 271 | + $config = $r->getValue($this->factory); |
| 272 | + |
| 273 | + $this->assertArrayHasKey('aliases', $config, 'Missing aliases from default service config'); |
| 274 | + $this->assertArrayHasKey('router', $config['aliases'], 'Missing "router" alias from default service config'); |
| 275 | + } |
194 | 276 | }
|
0 commit comments