Skip to content

Commit

Permalink
Fixed merging metadata from IEntityProvider with config [Fixes #299]
Browse files Browse the repository at this point in the history
Introduced in 4cda9bb IEntityProvider cannot change already configured namespace

[#88]
  • Loading branch information
fprochazka committed May 27, 2017
1 parent aea71c4 commit 530662e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Kdyby/Doctrine/DI/OrmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,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;
}
}

Expand Down
17 changes: 17 additions & 0 deletions tests/KdybyTests/Doctrine/Extension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
10 changes: 10 additions & 0 deletions tests/KdybyTests/Doctrine/config/entity-provider-merging.neon
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions tests/KdybyTests/Doctrine/models2/Models2Extension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* This file is part of the Kdyby (http://www.kdyby.org)
*
* Copyright (c) 2008 Filip Procházka ([email protected])
*
* For the full copyright and license information, please view the file license.txt that was distributed with this source code.
*/

namespace KdybyTests\Doctrine\Models2;

use Kdyby\Doctrine\DI\IEntityProvider;
use Nette\DI\CompilerExtension;

class Models2Extension extends CompilerExtension implements IEntityProvider
{

public function getEntityMappings()
{
return [
__NAMESPACE__ => __DIR__,
];
}

}

0 comments on commit 530662e

Please sign in to comment.