public function testTransaction()
 {
     $con = \Propel::getConnection();
     $service = new TransactionLifeCycle();
     $a = new Book();
     $faulty = new Book();
     $b = new Book();
     $ctx = $this->setUpEventHandlers($service);
     $faulty->setRawTitle(new \stdClass());
     $con->beginTransaction();
     try {
         $a->save();
         $faulty->save();
         $b->save();
         $this->fail("Transaction handling");
     } catch (\Exception $e) {
         $con->rollBack();
     }
     $this->assertEquals(false, $a->commited || $a->rolledback, 'Commited and rolledback hooks are not run if DB transaction didn\'t commit');
     $this->assertClearCache($service);
     $faulty->setTitle("test");
     $faulty->enableTransactionError();
     $con->beginTransaction();
     try {
         $a->save();
         $faulty->save();
         $b->save();
         $con->commit();
         $this->fail("Transaction faulty commit handling");
     } catch (\Exception $e) {
         $con->rollBack();
     }
     $this->assertEquals(true, $a->rolledback, 'Commited model was rolled back');
     $this->assertEquals(false, $b->rolledback || $faulty->rolledback, 'Uncommited models were not rolled back');
     $this->assertClearCache($service);
     $con->beginTransaction();
     try {
         $a->save();
         $b->save();
         $con->commit();
     } catch (\Exception $e) {
         $this->fail("Successful commit");
     }
     $this->assertClearCache($service);
     $ctx = $this->setUpEventHandlers('connection.commit.pre', $service);
     $a->setTitle("test");
     $a->save();
     $this->assertEventTriggered('Transaction events on singular model', $ctx, 1);
     $this->assertClearCache($service, 'Single commit');
 }
 public function testQueryModelClassOverride()
 {
     $manualFirst = 'Glorpen\\Propel\\PropelBundle\\Tests\\Fixtures\\Model\\ManualBook';
     $manualSecond = 'Glorpen\\Propel\\PropelBundle\\Tests\\Fixtures\\Model\\ManualSecondBook';
     \Propel::disableInstancePooling();
     $o = $this->setUpListener();
     $p = new TestOMProvider(function ($row, $cols) use($manualFirst, $manualSecond) {
         if ($row[0] == 1) {
             return $manualFirst;
         } else {
             return $manualSecond;
         }
     }, array($manualFirst => self::$modelClass, $manualSecond => self::$modelClass));
     $o->addProvider($p);
     $b = new Book();
     $b->setTitle("extended-title");
     $b->save();
     $b = new Book();
     $b->setTitle("extended-title2");
     $b->save();
     $manual1 = BookQuery::create()->filterById(1)->findOne();
     $this->assertInstanceOf($manualFirst, $manual1);
     $manual2 = BookQuery::create()->filterById(2)->findOne();
     $this->assertInstanceOf($manualSecond, $manual2);
 }