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

Commit 4c6fa92

Browse files
committed
Added more helpful errors for a bad configuration
1 parent 2318ea3 commit 4c6fa92

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/AbstractFactory/ConfigAbstractFactory.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ public function __invoke(\Interop\Container\ContainerInterface $container, $requ
5555
if (!is_array($dependencies)
5656
|| !array_key_exists($requestedName, $dependencies)
5757
|| !is_array($dependencies[$requestedName])
58-
|| $dependencies[$requestedName] !== array_values(array_map('strval', $dependencies[$requestedName]))
5958
) {
60-
throw new ServiceNotCreatedException('Dependencies config must exist and be an array of strings');
59+
throw new ServiceNotCreatedException('Dependencies config must exist and be an array');
6160
}
6261

6362
$serviceDependencies = $dependencies[$requestedName];
63+
64+
if ($serviceDependencies !== array_values(array_map('strval', $serviceDependencies))) {
65+
$problem = json_encode(array_map('gettype', $serviceDependencies));
66+
throw new ServiceNotCreatedException('Service message must be an array of strings, ' . $problem . ' given');
67+
}
68+
6469
$arguments = array_map([$container, 'get'], $serviceDependencies);
6570

6671
return new $requestedName(...$arguments);

test/AbstractFactory/ConfigAbstractFactoryTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function testExceptsWhenServiceConfigIsNotArray()
191191
]
192192
);
193193
self::expectException(ServiceNotCreatedException::class);
194-
self::expectExceptionMessage('Dependencies config must exist and be an array of strings');
194+
self::expectExceptionMessage('Dependencies config must exist and be an array');
195195

196196
$abstractFactory($serviceManager, 'Dirk_Gently');
197197
}
@@ -207,7 +207,7 @@ public function testExceptsWhenServiceConfigDoesNotExist()
207207
]
208208
);
209209
self::expectException(ServiceNotCreatedException::class);
210-
self::expectExceptionMessage('Dependencies config must exist and be an array of strings');
210+
self::expectExceptionMessage('Dependencies config must exist and be an array');
211211

212212
$abstractFactory($serviceManager, 'Dirk_Gently');
213213
}
@@ -225,7 +225,7 @@ public function testExceptsWhenServiceConfigForRequestedNameIsNotArray()
225225
]
226226
);
227227
self::expectException(ServiceNotCreatedException::class);
228-
self::expectExceptionMessage('Dependencies config must exist and be an array of strings');
228+
self::expectExceptionMessage('Dependencies config must exist and be an array');
229229

230230
$abstractFactory($serviceManager, 'Dirk_Gently');
231231
}
@@ -248,8 +248,10 @@ public function testExceptsWhenServiceConfigForRequestedNameIsNotArrayOfStrings(
248248
]
249249
);
250250
self::expectException(ServiceNotCreatedException::class);
251-
self::expectExceptionMessage('Dependencies config must exist and be an array of strings');
251+
self::expectExceptionMessage(
252+
'Service message must be an array of strings, ["string","string","string","integer"] given'
253+
);
252254

253-
$abstractFactory($serviceManager, 'Dirk_Gently');
255+
$abstractFactory($serviceManager, 'DirkGently');
254256
}
255257
}

0 commit comments

Comments
 (0)