Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 7ea20b0

Browse files
committed
Merge branch 'hotfix/servicemanager-109' into develop
Forward port #114
2 parents 275f7a2 + 78bc43b commit 7ea20b0

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

Diff for: CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ for full details on how to migrate your v2 application.
5757
`Zend\Json\Json::decode()` if it is available. If neither are available, an
5858
exception is now thrown.
5959

60-
## 2.7.4 - TBD
60+
## 2.7.4 - 2016-04-03
6161

6262
### Added
6363

@@ -73,7 +73,9 @@ for full details on how to migrate your v2 application.
7373

7474
### Fixed
7575

76-
- Nothing.
76+
- [#114](https://github.com/zendframework/zend-mvc/pull/114) fixes an issue in
77+
the `ServiceLocatorAware` initializer whereby plugin manager instances were
78+
falsely identified as the container instance when under zend-servicemanager v2.
7779

7880
## 2.7.3 - 2016-03-08
7981

Diff for: src/Service/ServiceManagerConfig.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,11 @@ public function __construct(array $config = [])
111111
},
112112
'ServiceManagerAwareInitializer' => function ($first, $second) {
113113
if ($first instanceof ContainerInterface) {
114+
// zend-servicemanager v3
114115
$container = $first;
115116
$instance = $second;
116117
} else {
118+
// zend-servicemanager v2
117119
$container = $second;
118120
$instance = $first;
119121
}
@@ -129,10 +131,16 @@ public function __construct(array $config = [])
129131
}
130132
},
131133
'ServiceLocatorAwareInitializer' => function ($first, $second) {
132-
if ($first instanceof ContainerInterface) {
134+
if ($first instanceof AbstractPluginManager) {
135+
// Edge case under zend-servicemanager v2
136+
$container = $second;
137+
$instance = $first;
138+
} elseif ($first instanceof ContainerInterface) {
139+
// zend-servicemanager v3
133140
$container = $first;
134141
$instance = $second;
135142
} else {
143+
// zend-servicemanager v2
136144
$container = $second;
137145
$instance = $first;
138146
}

Diff for: test/Service/ServiceManagerConfigTest.php

+73
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use ReflectionClass;
1414
use stdClass;
1515
use Zend\EventManager\EventManager;
16+
use Zend\Mvc\Controller\PluginManager;
1617
use Zend\Mvc\Service\ServiceManagerConfig;
1718
use Zend\ServiceManager\Factory\InvokableFactory;
1819
use Zend\ServiceManager\ServiceManager;
@@ -42,6 +43,16 @@ protected function setUp()
4243
$this->config->configureServiceManager($this->services);
4344
}
4445

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+
4556
/**
4657
* Create an event manager instance based on zend-eventmanager version
4758
*
@@ -225,4 +236,66 @@ public function testCreatesAFactoryForTheServiceManagerThatReturnsIt()
225236
$this->assertTrue($serviceManager->has('ServiceManager'), 'Missing ServiceManager service!');
226237
$this->assertSame($serviceManager, $serviceManager->get('ServiceManager'));
227238
}
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+
}
228301
}

0 commit comments

Comments
 (0)