|
13 | 13 | use ReflectionClass;
|
14 | 14 | use stdClass;
|
15 | 15 | use Zend\EventManager\EventManager;
|
| 16 | +use Zend\Mvc\Controller\PluginManager; |
16 | 17 | use Zend\Mvc\Service\ServiceManagerConfig;
|
17 | 18 | use Zend\ServiceManager\Factory\InvokableFactory;
|
18 | 19 | use Zend\ServiceManager\ServiceManager;
|
@@ -42,6 +43,16 @@ protected function setUp()
|
42 | 43 | $this->config->configureServiceManager($this->services);
|
43 | 44 | }
|
44 | 45 |
|
| 46 | + /** |
| 47 | + * Is this a v2 service manager? |
| 48 | + * |
| 49 | + * @return bool |
| 50 | + */ |
| 51 | + public function isV2ServiceManager() |
| 52 | + { |
| 53 | + return (! method_exists($this->services, 'configure')); |
| 54 | + } |
| 55 | + |
45 | 56 | /**
|
46 | 57 | * Create an event manager instance based on zend-eventmanager version
|
47 | 58 | *
|
@@ -225,4 +236,66 @@ public function testCreatesAFactoryForTheServiceManagerThatReturnsIt()
|
225 | 236 | $this->assertTrue($serviceManager->has('ServiceManager'), 'Missing ServiceManager service!');
|
226 | 237 | $this->assertSame($serviceManager, $serviceManager->get('ServiceManager'));
|
227 | 238 | }
|
| 239 | + |
| 240 | + /** |
| 241 | + * @see https://github.com/zendframework/zend-servicemanager/issues/109 |
| 242 | + */ |
| 243 | + public function testServiceLocatorAwareInitializerCanInjectPluginManagers() |
| 244 | + { |
| 245 | + if (! $this->isV2ServiceManager()) { |
| 246 | + $this->markTestSkipped(sprintf( |
| 247 | + '%s verifies backwards compatibility with the v2 series of zend-servicemanager', |
| 248 | + __FUNCTION__ |
| 249 | + )); |
| 250 | + } |
| 251 | + |
| 252 | + $this->services->setFactory('test-plugins', function () { |
| 253 | + return new PluginManager(); |
| 254 | + }); |
| 255 | + |
| 256 | + $deprecated = false; |
| 257 | + set_error_handler(function ($errno, $errstr) use (&$deprecated) { |
| 258 | + $deprecated = true; |
| 259 | + }, E_USER_DEPRECATED); |
| 260 | + |
| 261 | + $plugins = $this->services->get('test-plugins'); |
| 262 | + |
| 263 | + restore_error_handler(); |
| 264 | + |
| 265 | + $this->assertSame($this->services, $plugins->getServiceLocator()); |
| 266 | + $this->assertTrue($deprecated, 'Deprecation notice for ServiceLocatorAwareInitializer was not triggered'); |
| 267 | + } |
| 268 | + |
| 269 | + /** |
| 270 | + * @see https://github.com/zendframework/zend-servicemanager/issues/109 |
| 271 | + */ |
| 272 | + public function testServiceLocatorAwareInitializerWillNotReinjectPluginManagers() |
| 273 | + { |
| 274 | + if (! $this->isV2ServiceManager()) { |
| 275 | + $this->markTestSkipped(sprintf( |
| 276 | + '%s verifies backwards compatibility with the v2 series of zend-servicemanager', |
| 277 | + __FUNCTION__ |
| 278 | + )); |
| 279 | + } |
| 280 | + |
| 281 | + $altServices = new ServiceManager(); |
| 282 | + $this->services->setFactory('test-plugins', function () use ($altServices) { |
| 283 | + return new PluginManager($altServices); |
| 284 | + }); |
| 285 | + |
| 286 | + $deprecated = false; |
| 287 | + set_error_handler(function ($errno, $errstr) use (&$deprecated) { |
| 288 | + $deprecated = true; |
| 289 | + }, E_USER_DEPRECATED); |
| 290 | + |
| 291 | + $plugins = $this->services->get('test-plugins'); |
| 292 | + |
| 293 | + restore_error_handler(); |
| 294 | + |
| 295 | + $this->assertSame($altServices, $plugins->getServiceLocator()); |
| 296 | + $this->assertFalse( |
| 297 | + $deprecated, |
| 298 | + 'Deprecation notice for ServiceLocatorAwareInitializer was triggered, but should not have been' |
| 299 | + ); |
| 300 | + } |
228 | 301 | }
|
0 commit comments