public function testCreateMany2One() { $this->assertCount(0, $this->logrepo->findAll()); $comment = new Comment(); $art1 = new RelatedArticle(); $art1->setTitle('Title'); $art1->setContent('Content'); $comment->setArticle($art1); $comment->setSubject('Subject'); $comment->setMessage('Message'); $this->em->persist($comment); $this->em->flush(); $logs = $this->mainlogrepo->findAll(); $this->assertCount(3, $logs); foreach ($logs as $log) { if ($log instanceof LogParent) { $this->assertEquals($log->getChildClass(), get_class($comment)); $this->assertEquals($log->getChildId(), $comment->getId()); $this->assertEquals($log->getObjectClass(), get_class($art1)); $this->assertEquals($log->getObjectId(), $art1->getId()); } else { if ($log->getObjectClass() == get_class($art1)) { $data = $log->getData(); $this->assertEquals($log->getObjectId(), $art1->getId()); $this->assertArrayHasKey('title', $data); $this->assertArrayHasKey('content', $data); $this->assertEquals('Title', $data['title']); $this->assertEquals('Content', $data['content']); } else { if ($log->getObjectClass() == get_class($comment)) { $data = $log->getData(); $this->assertEquals($log->getObjectId(), $comment->getId()); $this->assertArrayHasKey('subject', $data); $this->assertArrayHasKey('message', $data); $this->assertEquals('Subject', $data['subject']); $this->assertEquals('Message', $data['message']); } } } } }
public function addComment(Comment $comment) { $comment->setArticle($this); $this->comments[] = $comment; }
public function testApplyChangeSetMany2One() { $comment = new Comment(); $art1 = new RelatedArticle(); $art1->setTitle('Title'); $art1->setContent('Content'); $art2 = new RelatedArticle(); $art2->setTitle('Title2'); $art2->setContent('Content2'); $comment->setArticle($art1); $comment->setSubject('Subject'); $comment->setMessage('Message'); $this->em->persist($comment); $this->em->persist($art1); $this->em->persist($art2); $this->em->flush(); $comment->setArticle($art2); $comment->setScheduledChangeDate(new \DateTime("+ 1 second")); $this->em->persist($comment); $this->em->flush(); $changes = $this->changeRepo->findAll(); $this->assertCount(1, $changes); $change = array_pop($changes); $return = $this->changeRepo->applyChangeSet($change); $this->assertFalse($return); $this->assertEquals('Title', $comment->getArticle()->getTitle()); sleep(1); $return = $this->changeRepo->applyChangeSet($change); $this->assertNotEquals(false, $return); $this->assertEquals('Title2', $return->getArticle()->getTitle()); }