/**
  * @param string $name
  *
  * @return object
  */
 protected function getFixture($name)
 {
     $manager = $this->getKernel()->getContainer()->get('doctrine.orm.default_entity_manager');
     if (!$this->referenceRepository->hasReference($name)) {
         if (isset(static::$referenceRepositoryData[$name])) {
             $reference = $manager->getReference(static::$referenceRepositoryData[$name]['class'], static::$referenceRepositoryData[$name]['identifier']);
             $this->referenceRepository->setReference($name, $reference);
         }
     }
     return $this->referenceRepository->getReference($name);
 }
Ejemplo n.º 2
0
 /**
  * @param string $referenceName
  * @param bool $persist
  * @param callable $objectLoader
  * @return mixed
  */
 protected function load($referenceName, $persist, \Closure $objectLoader, $defaultReferenceName = '')
 {
     if (is_null($referenceName)) {
         $referenceName = $defaultReferenceName;
     }
     if ($this->referenceRepository->hasReference($referenceName)) {
         return $this->referenceRepository->getReference($referenceName);
     }
     $object = $objectLoader($this, $referenceName);
     if ($persist) {
         $this->objectManager->persist($object);
     }
     $this->referenceRepository->setReference($referenceName, $object);
     return $object;
 }
Ejemplo n.º 3
0
 /**
  * Set the reference entry identified by $name
  * and referenced to managed $object. If $name
  * already is set, it overrides it
  * 
  * @param string $name
  * @param object $object - managed object
  * @see Doctrine\Common\DataFixtures\ReferenceRepository::setReference
  * @return void
  */
 public function setReference($name, $object)
 {
     $this->referenceRepository->setReference($name, $object);
 }
Ejemplo n.º 4
0
 /**
  * Sets a reference to the object
  *
  * @param object $object
  */
 public function setReference($object)
 {
     if ($this->referenceRepository && $object instanceof ReferableInterface) {
         $this->referenceRepository->setReference(get_class($object) . '.' . $object->getReference(), $object);
     }
 }
 public function testGetIdentifierWhenHasNotBeenManagedYetByUnitOfWork()
 {
     $role = new Role();
     $identitiesExpected = ['id' => 1];
     /** @var UnitOfWork | ProphecyInterface $uow */
     $uow = $this->prophesize(UnitOfWork::class);
     $uow->isInIdentityMap($role)->shouldBeCalledTimes(2)->willReturn(true, false);
     /** @var ClassMetadata $classMetadata */
     $classMetadata = $this->prophesize(ClassMetadata::class);
     $classMetadata->getIdentifierValues($role)->shouldBeCalled()->willReturn($identitiesExpected);
     /** @var EntityManagerInterface | ProphecyInterface $em */
     $em = $this->prophesize(EntityManagerInterface::class);
     $em->getUnitOfWork()->shouldBeCalled()->willReturn($uow);
     $em->getClassMetadata(Role::class)->shouldBeCalled()->willReturn($classMetadata);
     $referenceRepository = new ReferenceRepository($em->reveal());
     $referenceRepository->setReference('entity', $role);
     $identities = $referenceRepository->getIdentities();
     $this->assertEquals($identitiesExpected, $identities['entity']);
 }