Ejemplo n.º 1
0
 public function testRollbackOnException()
 {
     $eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $eventDispatcher->expects($this->once())->method('dispatch')->will($this->throwException(new \RuntimeException()));
     $entityManager = $this->getEntityManager();
     $entityManager->getConnection()->expects($this->once())->method('rollBack');
     $transaction = new TransactionEvents();
     $transaction->addFirstPass('event', new ForumEvent());
     $this->setExpectedException('RuntimeException');
     $dispatcher = new TransactionDispatcher($entityManager, $eventDispatcher);
     $dispatcher->dispatch($transaction);
 }
Ejemplo n.º 2
0
 /**
  * Dispatches the TransactionEvents in two passes
  * @param    TransactionEvents
  */
 public function dispatch(TransactionEvents $transaction)
 {
     try {
         $this->em->getConnection()->beginTransaction();
         foreach ($transaction->getFirstPass() as $eventName => $event) {
             $this->dispatcher->dispatch($eventName, $event);
         }
         foreach ($transaction->getFirstPass() as $eventName => $event) {
             $this->applyEventChangeSet($event);
         }
         $this->em->flush();
         foreach ($transaction->getSecondPass() as $eventName => $event) {
             $this->dispatcher->dispatch($eventName, $event);
         }
         foreach ($transaction->getSecondPass() as $eventName => $event) {
             $this->applyEventChangeSet($event);
         }
         $this->em->flush();
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollBack();
         throw $e;
     }
 }
Ejemplo n.º 3
0
 public function testEmptyTransactionYieldsEmptyArray()
 {
     $transaction = new TransactionEvents();
     $this->assertSame(array(), $transaction->getFirstPass());
     $this->assertSame(array(), $transaction->getSecondPass());
 }