/**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $blogTagRecords = [];
     for ($i = 0; $i < 10; ++$i) {
         $blogTagRecords[] = ['title' => 'Tag #' . ($i + 1), 'description' => 'Description of the Tag #' . ($i + 1)];
     }
     foreach ($blogTagRecords as $blogTagRecord) {
         $blogTag = new BlogTag();
         $blogTag->setTitle($blogTagRecord['title']);
         $blogTag->setDescription($blogTagRecord['description']);
         $manager->persist($blogTag);
         $manager->flush();
         $this->referenceRepository->addReference('blog-tag-' . $blogTag->getId(), $blogTag);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $pageRecords = [['name' => 'about', 'title' => 'A propos', 'content' => '
         **ok** *about* ***a propos***
         ### Hey
         ']];
     foreach ($pageRecords as $pageRecord) {
         $page = new Page();
         $page->setName($pageRecord['name']);
         $page->setTitle($pageRecord['title']);
         $page->setContent($pageRecord['content']);
         $manager->persist($page);
         $manager->flush();
         $this->referenceRepository->addReference('page-' . $page->getId(), $page);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $blogArticleRecords = [];
     for ($i = 0; $i < 10; ++$i) {
         $blogArticleRecords[] = ['title' => 'Article #' . ($i + 1), 'description' => 'Description of Article #' . ($i + 1), 'content' => 'Content of Article #' . ($i + 1)];
     }
     foreach ($blogArticleRecords as $blogArticleRecord) {
         $blogArticle = new BlogArticle();
         $blogArticle->setTitle($blogArticleRecord['title']);
         $blogArticle->setDescription($blogArticleRecord['description']);
         $blogArticle->setContent($blogArticleRecord['content']);
         $blogArticle->setImageUrl('');
         $blogArticle->setPublicationDate(new \DateTime());
         $manager->persist($blogArticle);
         $manager->flush();
         $this->referenceRepository->addReference('blog-article-' . $blogArticle->getId(), $blogArticle);
     }
 }
 public function testReferenceEntry()
 {
     $em = $this->getMockAnnotationReaderEntityManager();
     $role = new TestEntity\Role();
     $role->setName('admin');
     $meta = $em->getClassMetadata(self::TEST_ENTITY_ROLE);
     $meta->getReflectionProperty('id')->setValue($role, 1);
     $referenceRepo = new ReferenceRepository($em);
     $referenceRepo->addReference('test', $role);
     $references = $referenceRepo->getReferences();
     $this->assertEquals(1, count($references));
     $this->assertArrayHasKey('test', $references);
     $this->assertInstanceOf(self::TEST_ENTITY_ROLE, $references['test']);
 }
Ejemplo n.º 5
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::addReference
  * @return void
  */
 public function addReference($name, $object)
 {
     $this->referenceRepository->addReference($name, $object);
 }
 public function testThrowsExceptionAddingDuplicatedReference()
 {
     $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager());
     $referenceRepository->addReference('duplicated_reference', new \stdClass());
     $this->expectException(\BadMethodCallException::class);
     $this->expectExceptionMessage('Reference to: (duplicated_reference) already exists, use method setReference in order to override it');
     $referenceRepository->addReference('duplicated_reference', new \stdClass());
 }
 public function testReferenceMultipleEntries()
 {
     $em = $this->getMockSqliteEntityManager();
     $referenceRepository = new ReferenceRepository($em);
     $em->getEventManager()->addEventSubscriber(new ORMReferenceListener($referenceRepository));
     $schemaTool = new SchemaTool($em);
     $schemaTool->createSchema(array($em->getClassMetadata(self::TEST_ENTITY_ROLE)));
     $role = new TestEntity\Role();
     $role->setName('admin');
     $em->persist($role);
     $referenceRepository->addReference('admin', $role);
     $referenceRepository->addReference('duplicate', $role);
     $em->flush();
     $em->clear();
     $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $referenceRepository->getReference('admin'));
     $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $referenceRepository->getReference('duplicate'));
 }