Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add test

  • Loading branch information...
commit ce6552bb16957620252523d95dd2a4992cc3a48f 1 parent 4768e06
@bakura10 bakura10 authored
View
1  src/DoctrineORMModule/Module.php
@@ -113,6 +113,7 @@ public function onBootstrap(EventInterface $e)
});
$config = $app->getServiceManager()->get('Config');
+ $app->getServiceManager()->get('doctrine.entity_resolver.orm_default');
if (
isset($config['zenddevelopertools']['profiler']['enabled'])
View
24 src/DoctrineORMModule/Options/EntityResolver.php
@@ -5,7 +5,7 @@
use InvalidArgumentException;
use Zend\Stdlib\AbstractOptions;
-class EntityResolver
+class EntityResolver extends AbstractOptions
{
/**
* Set the configuration key for the EventManager. Event manager key
@@ -18,7 +18,7 @@ class EntityResolver
/**
* An array that maps a class name (or interface name) to another class
- * name (and with an optional mapping)
+ * name
*
* @var array
*/
@@ -46,23 +46,21 @@ public function getEventManager()
/**
* @param array $resolvers
- * @throws \InvalidArgumentException
+ * @throws InvalidArgumentException
*/
public function setResolvers(array $resolvers)
{
- foreach ($resolvers as $entity => $resolveParameters) {
- if (!isset($resolveParameters['resolved_entity_name'])) {
- throw new InvalidArgumentException(
- 'The resolved entity name for %s has not been set',
- $entity
+ foreach ($resolvers as $old => $new) {
+ if (!class_exists($new)) {
+ throw new InvalidArgumentException(sprintf(
+ '%s is resolved to the entity %s, which does not exist',
+ $old,
+ $new
+ )
);
}
- if (!isset($resolveParameters['mapping'])) {
- $resolveParameters['mapping'] = array();
- }
-
- $this->resolvers[$entity] = $resolveParameters;
+ $this->resolvers[$old] = $new;
}
}
View
10 src/DoctrineORMModule/Service/EntityResolverFactory.php
@@ -20,6 +20,7 @@
namespace DoctrineORMModule\Service;
use Doctrine\ORM\EntityManager;
+use Doctrine\ORM\Events;
use Doctrine\ORM\Tools\ResolveTargetEntityListener;
use DoctrineModule\Service\AbstractFactory;
use Zend\ServiceManager\ServiceLocatorInterface;
@@ -38,14 +39,11 @@ public function createService(ServiceLocatorInterface $serviceLocator)
$targetEntityListener = new ResolveTargetEntityListener();
- foreach ($resolvers as $entity => $resolveParameters) {
- $resolvedEntityName = $resolveParameters['resolved_entity_name'];
- $mapping = $resolveParameters['mapping'];
-
- $targetEntityListener->addResolveTargetEntity($entity, $resolvedEntityName, $mapping);
+ foreach ($resolvers as $oldEntity => $newEntity) {
+ $targetEntityListener->addResolveTargetEntity($oldEntity, $newEntity, array());
}
- $eventManager->addEventListener($targetEntityListener);
+ $eventManager->addEventListener(Events::loadClassMetadata, $targetEntityListener);
return $eventManager;
}
View
7 tests/Bootstrap.php
@@ -49,6 +49,12 @@
__DIR__ . '/DoctrineORMModuleTest/Assets/Entity'
)
);
+$config['doctrine']['entity_resolver']['orm_default'] = array(
+ 'resolvers' => array(
+ 'DoctrineORMModuleTest\Assets\Entity\TargetInterface' =>
+ 'DoctrineORMModuleTest\Assets\Entity\TargetEntity'
+ )
+);
$config['doctrine']['driver']['orm_default']['drivers']['DoctrineORMModuleTest\Assets\Entity'] = 'test';
$config['doctrine']['connection']['orm_default'] = array(
'configuration' => 'orm_default',
@@ -61,4 +67,5 @@
);
$serviceManager->setService('Config', $config);
+$serviceManager->get('doctrine.entity_resolver.orm_default');
TestCase::setServiceManager($serviceManager);
View
24 tests/DoctrineORMModuleTest/Assets/Entity/ResolveTarget.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace DoctrineORMModuleTest\Assets\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ */
+class ResolveTarget
+{
+ /**
+ * @ORM\Id
+ * @ORM\Column(type="integer")
+ * @ORM\GeneratedValue(strategy="AUTO")
+ */
+ private $id;
+
+ /**
+ * @ORM\OneToOne(targetEntity="TargetInterface")
+ */
+ protected $target;
+}
+
View
18 tests/DoctrineORMModuleTest/Assets/Entity/TargetEntity.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace DoctrineORMModuleTest\Assets\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ */
+class TargetEntity implements TargetInterface
+{
+ /**
+ * @ORM\Id
+ * @ORM\Column(type="integer")
+ * @ORM\GeneratedValue(strategy="AUTO")
+ */
+ private $id;
+}
View
8 tests/DoctrineORMModuleTest/Assets/Entity/TargetInterface.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace DoctrineORMModuleTest\Assets\Entity;
+
+interface TargetInterface
+{
+
+}
View
47 tests/DoctrineORMModuleTest/Service/EntityResolverFactoryTest.php
@@ -0,0 +1,47 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace DoctrineORMModuleTest\Service;
+
+use DoctrineORMModuleTest\Framework\TestCase as TestCase;
+use DoctrineORMModule\Service\EntityResolverFactory;
+use Doctrine\ORM\Configuration as ORMConfiguration;
+use Zend\ServiceManager\ServiceManager;
+
+
+class EntityResolverFactoryTest extends TestCase
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp()
+ {
+ parent::setUp();
+ }
+
+ public function testCanResolveTargetEntity()
+ {
+ $em = $this->getEntityManager();
+ $classMetadata = $em->getClassMetadata('DoctrineORMModuleTest\Assets\Entity\ResolveTarget');
+ $meta = $classMetadata->associationMappings;
+
+ $this->assertSame('DoctrineORMModuleTest\Assets\Entity\TargetEntity', $meta['target']['targetEntity']);
+ }
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.