Esempio n. 1
0
 /**
  * Test that transactions behave correctly on nested saveMany calls.
  *
  * @return void
  */
 public function testTransactionOnNestedSaveMany()
 {
     $this->loadFixtures('Post');
     $Post = new TestPost();
     $Post->getEventManager()->attach(array($this, 'nestedSaveMany'), 'Model.afterSave');
     // begin -> [ begin -> commit ] -> commit
     $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
     $db->expects($this->exactly(2))->method('begin')->will($this->returnValue(true));
     $db->expects($this->exactly(2))->method('commit');
     $db->expects($this->never())->method('rollback');
     $Post->setDataSourceObject($db);
     $data = array(array('author_id' => 1, 'title' => 'Outer Post'));
     $Post->dataForAfterSave = array(array('author_id' => 1, 'title' => 'Inner Post'));
     $this->assertTrue($Post->saveMany($data));
     // begin -> [  begin(false) ] -> commit
     $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
     $db->expects($this->at(0))->method('begin')->will($this->returnValue(true));
     $db->expects($this->at(1))->method('begin')->will($this->returnValue(false));
     $db->expects($this->once())->method('commit');
     $db->expects($this->never())->method('rollback');
     $Post->setDataSourceObject($db);
     $data = array(array('author_id' => 1, 'title' => 'Outer Post'));
     $Post->dataForAfterSave = array(array('author_id' => 1, 'title' => 'Inner Post'));
     $this->assertTrue($Post->saveMany($data));
     // begin -> [ begin -> rollback ] -> rollback
     $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
     $db->expects($this->exactly(2))->method('begin')->will($this->returnValue(true));
     $db->expects($this->never())->method('commit');
     $db->expects($this->exactly(2))->method('rollback');
     $Post->setDataSourceObject($db);
     $data = array(array('author_id' => 1, 'title' => 'Outer Post'));
     $Post->dataForAfterSave = array(array('author_id' => 1, 'title' => 'Inner Post', 'body' => $db->expression('PDO_EXCEPTION()')));
     try {
         $Post->saveMany($data);
         $this->fail('No exception thrown');
     } catch (Exception $e) {
     }
 }
Esempio n. 2
0
 /**
  * test saveMany with transactions and ensure there is no missing rollback.
  *
  * @return void
  */
 public function testSaveManyTransactionNoRollback()
 {
     $this->loadFixtures('Post');
     $db = $this->getMock('DboSource', array('begin', 'connect', 'rollback', 'describe'));
     $db->expects($this->once())->method('describe')->will($this->returnValue(array()));
     $db->expects($this->once())->method('rollback');
     $Post = new TestPost();
     $Post->setDataSourceObject($db);
     $Post->validate = array('title' => array('rule' => array('notEmpty')));
     $data = array(array('author_id' => 1, 'title' => 'New Fourth Post'), array('author_id' => 1, 'title' => ''));
     $Post->saveMany($data, array('validate' => true));
 }