public function testRevert() { $this->assertCount(0, $this->logrepo->findAll()); $art0 = new Article(); $art0->setTitle('Title'); $this->em->persist($art0); $this->em->flush(); $logs = $this->logrepo->findAll(); $this->assertCount(1, $logs); $art0->setTitle('newTitle'); $this->em->persist($art0); $this->em->flush(); $this->em->clear(); $logs = $this->logrepo->findAll(); $this->assertCount(2, $logs); $log = array_pop($logs); $this->logrepo->revertTo($log); $this->assertCount(1, $logs); $artclass = get_class($art0); $artid = $art0->getId(); $art0 = $this->em->find($artclass, $artid); $this->assertEquals('Title', $art0->getTitle()); $this->em->remove($art0); $this->em->flush(); $art0 = $this->em->getRepository($artclass)->findOneBy(array('id' => $artid)); $this->assertNull($art0); $logs = $this->logrepo->findAll(); $this->assertCount(2, $logs); //use softdelete to remove and un-remove // $this->assertCount(2, $logs); // $log = array_pop($logs); // $this->assertEquals($log->getAction(), LoggableListener::ACTION_REMOVE); // $this->logrepo->revertTo($log); // $art0 = $this->em->find($artclass, $artid); // $this->assertNotNull($art0); }
public function testApplyCommandWithUserName() { $this->logrepo->getLoggableListener()->setUsername('testUser'); $art0 = new Article(); $art0->setTitle('Title'); $this->em->persist($art0); $this->em->flush(); $art0->setTitle('Title New'); $art0->setScheduledChangeDate(new \DateTime("+ 1 second")); $this->em->persist($art0); $this->em->flush(); $changes = $this->changeRepo->findAll(); $this->assertCount(1, $changes); $application = new Application(self::$kernel); $application->add(new ChangeCommand()); $command = $application->find('ibrows:loggable:change'); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName()), array('verbosity' => 2)); $this->assertRegExp('/Processed 0 changes/', $commandTester->getDisplay()); sleep(1); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName()), array('verbosity' => 2)); $this->assertRegExp('/Processed 1 changes/', $commandTester->getDisplay()); $logs = $this->logrepo->getLogsByObject($art0); $scheduledlog = array_pop($logs); $this->assertEquals('testUser', $scheduledlog->getUserName()); }