Skip to content

Commit 8bb28b3

Browse files
committed
Throw an exception of mappings looks like it is just an assoc array and not an array of arrays.
1 parent e453be6 commit 8bb28b3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Dflydev/Pimple/Provider/DoctrineOrm/DoctrineOrmServiceProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ public function register(\Pimple $app)
116116

117117
$chain = $app['orm.mapping_driver_chain.locator']($name);
118118
foreach ((array) $options['mappings'] as $entity) {
119+
if (!is_array($entity)) {
120+
throw new \InvalidArgumentException(
121+
"The 'orm.em.options' option 'mappings' should be an array of arrays."
122+
);
123+
}
124+
119125
if (!empty($entity['resources_namespace'])) {
120126
$entity['path'] = $app['psr0_resource_locator']->findFirstDirectory($entity['resources_namespace']);
121127
}

tests/Dflydev/Pimple/Provider/DoctrineOrm/DoctrineOrmServiceProviderTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,28 @@ public function testNameFromParamKey()
258258
$this->assertEquals('foo', $app['orm.em_name_from_param_key']('my.bar'));
259259
$this->assertEquals('baz', $app['orm.em_name_from_param_key']('my.baz'));
260260
}
261+
262+
/**
263+
* Test specifying an invalid mapping configuration (not an array of arrays)
264+
*
265+
* @expectedException InvalidArgumentException
266+
* @expectedExceptionMessage The 'orm.em.options' option 'mappings' should be an array of arrays.
267+
*/
268+
public function testInvalidMappingAsOption()
269+
{
270+
$app = $this->createMockDefaultApp();
271+
272+
$doctrineOrmServiceProvider = new DoctrineOrmServiceProvider;
273+
$doctrineOrmServiceProvider->register($app);
274+
275+
$app['orm.em.options'] = array(
276+
'mappings' => array(
277+
'type' => 'annotation',
278+
'namespace' => 'Foo\Entities',
279+
'path' => __DIR__.'/src/Foo/Entities',
280+
),
281+
);
282+
283+
$app['orm.ems.config'];
284+
}
261285
}

0 commit comments

Comments
 (0)