From 02aeeaa0ebb09e027090561896a872f71e405181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Sat, 27 May 2017 19:49:47 +0200 Subject: [PATCH] Fixed merging metadata from IEntityProvider with config [Fixes #299] Introduced in 4cda9bb8b251254f22f8e123b7e827ca0ca45483 IEntityProvider cannot change already configured namespace [#88] --- src/Kdyby/Doctrine/DI/OrmExtension.php | 4 +-- tests/KdybyTests/Doctrine/Extension.phpt | 17 ++++++++++++ .../config/entity-provider-merging.neon | 10 +++++++ .../Doctrine/models2/Models2Extension.php | 26 +++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tests/KdybyTests/Doctrine/config/entity-provider-merging.neon create mode 100644 tests/KdybyTests/Doctrine/models2/Models2Extension.php diff --git a/src/Kdyby/Doctrine/DI/OrmExtension.php b/src/Kdyby/Doctrine/DI/OrmExtension.php index f7246563..f448c909 100644 --- a/src/Kdyby/Doctrine/DI/OrmExtension.php +++ b/src/Kdyby/Doctrine/DI/OrmExtension.php @@ -258,11 +258,11 @@ protected function processEntityManager($name, array $defaults) if ($extension instanceof IEntityProvider) { $metadata = $extension->getEntityMappings(); Validators::assert($metadata, 'array'); - foreach ($metadata as $namespace => $config) { + foreach ($metadata as $namespace => $nsConfig) { if (array_key_exists($namespace, $config['metadata'])) { throw new Nette\Utils\AssertionException(sprintf('The namespace %s is already configured, provider cannot change it', $namespace)); } - $config['metadata'][$namespace] = $config; + $config['metadata'][$namespace] = $nsConfig; } } diff --git a/tests/KdybyTests/Doctrine/Extension.phpt b/tests/KdybyTests/Doctrine/Extension.phpt index 28b43fa5..8feef934 100644 --- a/tests/KdybyTests/Doctrine/Extension.phpt +++ b/tests/KdybyTests/Doctrine/Extension.phpt @@ -121,6 +121,23 @@ class ExtensionTest extends Tester\TestCase }, $default->getMetadataFactory()->getAllMetadata()); Assert::contains('KdybyTests\\Doctrine\\CmsArticle', $entityClasses); + Assert::notContains('KdybyTests\Doctrine\Models2\Foo', $entityClasses); + } + + + + public function testEntityMetadataMergingFromProvider() + { + $container = $this->createContainer('entity-provider-merging'); + + /** @var Kdyby\Doctrine\EntityManager $default */ + $default = $container->getByType('Kdyby\Doctrine\EntityManager'); + $entityClasses = array_map(function (ClassMetadata $class) { + return $class->getName(); + }, $default->getMetadataFactory()->getAllMetadata()); + + Assert::contains('KdybyTests\Doctrine\CmsArticle', $entityClasses); + Assert::contains('KdybyTests\Doctrine\Models2\Foo', $entityClasses); } diff --git a/tests/KdybyTests/Doctrine/config/entity-provider-merging.neon b/tests/KdybyTests/Doctrine/config/entity-provider-merging.neon new file mode 100644 index 00000000..c437cfa6 --- /dev/null +++ b/tests/KdybyTests/Doctrine/config/entity-provider-merging.neon @@ -0,0 +1,10 @@ +kdyby.doctrine: + driver: pdo_sqlite + memory: true + metadata: + KdybyTests\Doctrine: annotations(%appDir%/Doctrine/models) + targetEntityMappings: + KdybyTests\Doctrine\ICmsAddress: KdybyTests\Doctrine\CmsAddress + +extensions: + - KdybyTests\Doctrine\Models2\Models2Extension diff --git a/tests/KdybyTests/Doctrine/models2/Models2Extension.php b/tests/KdybyTests/Doctrine/models2/Models2Extension.php new file mode 100644 index 00000000..04364cb5 --- /dev/null +++ b/tests/KdybyTests/Doctrine/models2/Models2Extension.php @@ -0,0 +1,26 @@ + __DIR__, + ]; + } + +}