public function testConversion() { $tag = new Tag('timestamped'); $this->assertInstanceOf('Webforge\\Common\\DateTime\\DateTime', $time = $tag->getCreated()); $this->em->persist($tag); $this->em->flush(); $this->em->clear(); $this->assertInstanceOf('Webforge\\Common\\DateTime\\DateTime', $savedTime = $tag->getCreated()); $this->assertEquals($time, $savedTime); }
protected function helpConvertToEntities() { // wir gehen davon aus, dsas wir 2 collections haben die fertig hydriert sind // in unserem test ist das aber nicht so, deshalb machen wir das hier $hydrator = new UniqueEntityHydrator($this->em->getRepository('Psc\\Doctrine\\TestEntities\\Tag')); return new ArrayCollection($this->getToCollection(function ($id, $label) use($hydrator) { $entity = $hydrator->getEntity(compact('id', 'label')); if ($entity === NULL) { $entity = new Tag($label); } else { $entity->setLabel($label); // merge nicht vergessen :) } return $entity; })); }
/** * @dataProvider provideCollectionTypes */ public function testSynchronizeCollection($type) { if ($type === 'ref') { $this->article->addTag($u1 = new ArticleTag('Russland')); $this->article->addTag($u2 = new ArticleTag('Demonstration')); $this->article->addTag($d1 = new ArticleTag('Protest')); $this->article->addTag($d2 = new ArticleTag('Wahl')); $n1 = new ArticleTag('Präsidentenwahl'); } if ($type === 'id') { $this->article->addTag($u1 = new ArticleTag('Russland')); $u1->setId(1); $this->article->addTag($u2 = new ArticleTag('Demonstration')); $u2->setId(2); $this->article->addTag($d1 = new ArticleTag('Protest')); $d1->setId(4); $this->article->addTag($d2 = new ArticleTag('Wahl')); $d2->setId(5); $n1 = new ArticleTag('Präsidentenwahl'); $n1->setId(10); } if ($type === 'mixed') { $this->article->addTag($u1 = new ArticleTag('Russland')); $u1->setId(1); $this->article->addTag($u2 = new ArticleTag('Demonstration')); $this->article->addTag($d1 = new ArticleTag('Protest')); $d1->setId(4); $this->article->addTag($d2 = new ArticleTag('Wahl')); $d2->setId(5); $n1 = new ArticleTag('Präsidentenwahl'); } $this->assertEntityCollectionSame(new ArrayCollection(array($u1, $u2, $d1, $d2)), $this->article->getTags(), 'tags-initial'); $formTags = array($u1, $u2, $n1); $this->processor->synchronizeCollection('tags', $formTags); //print $this->processor->log; $this->assertEntityCollectionEquals(new ArrayCollection(array($n1)), $this->emm->getPersisted(), 'persisted'); $this->assertEntityCollectionEquals(new ArrayCollection(array($n1, $u1, $u2)), $this->article->getTags(), 'tags-processed'); }