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

Commit 2dcc55a

Browse files
committed
Merge branch 'hotfix/174' into develop
Forward port #174
2 parents c995e05 + 89ee4f2 commit 2dcc55a

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ All notable changes to this project will be documented in this file, in reverse
3636

3737
### Fixed
3838

39-
- Nothing.
39+
- [#174](https://github.com/zendframework/zend-servicemanager/pull/174) updates
40+
the `ConfigAbstractFactory` to allow the `config` service to be either an
41+
`array` or an `ArrayObject`; previously, only `array` was supported.
4042

4143
## 3.2.0 - 2016-12-19
4244

src/AbstractFactory/ConfigAbstractFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Zend\ServiceManager\AbstractFactory;
99

10+
use ArrayObject;
1011
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
1112
use Zend\ServiceManager\Factory\AbstractFactoryInterface;
1213

@@ -40,8 +41,8 @@ public function __invoke(\Interop\Container\ContainerInterface $container, $requ
4041

4142
$config = $container->get('config');
4243

43-
if (! is_array($config)) {
44-
throw new ServiceNotCreatedException('Config must be an array');
44+
if (! (is_array($config) || $config instanceof ArrayObject)) {
45+
throw new ServiceNotCreatedException('Config must be an array or an instance of ArrayObject');
4546
}
4647

4748
if (! array_key_exists(self::class, $config)) {

test/AbstractFactory/ConfigAbstractFactoryTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace ZendTest\ServiceManager\AbstractFactory;
99

10+
use ArrayObject;
1011
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
1112
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
1213
use Zend\ServiceManager\ServiceManager;
@@ -76,6 +77,39 @@ public function testCanCreate()
7677
self::assertFalse($abstractFactory->canCreate($serviceManager, ServiceManager::class));
7778
}
7879

80+
public function testCanCreateReturnsTrueWhenConfigIsAnArrayObject()
81+
{
82+
$abstractFactory = new ConfigAbstractFactory();
83+
$serviceManager = new ServiceManager();
84+
$serviceManager->setService(
85+
'config',
86+
new ArrayObject([
87+
ConfigAbstractFactory::class => [
88+
InvokableObject::class => [],
89+
]
90+
])
91+
);
92+
93+
self::assertTrue($abstractFactory->canCreate($serviceManager, InvokableObject::class));
94+
self::assertFalse($abstractFactory->canCreate($serviceManager, ServiceManager::class));
95+
}
96+
97+
public function testFactoryCanCreateInstancesWhenConfigIsAnArrayObject()
98+
{
99+
$abstractFactory = new ConfigAbstractFactory();
100+
$serviceManager = new ServiceManager();
101+
$serviceManager->setService(
102+
'config',
103+
new ArrayObject([
104+
ConfigAbstractFactory::class => [
105+
InvokableObject::class => [],
106+
]
107+
])
108+
);
109+
110+
self::assertInstanceOf(InvokableObject::class, $abstractFactory($serviceManager, InvokableObject::class));
111+
}
112+
79113
public function testInvokeWithInvokableClass()
80114
{
81115
$abstractFactory = new ConfigAbstractFactory();

0 commit comments

Comments
 (0)