Esempio n. 1
0
 /**
  * test saveAll with transactions and ensure there is no missing rollback.
  *
  * @return void
  */
 public function testSaveAllAssociatedTransactionNoRollback()
 {
     $this->loadFixtures('Post', 'Author');
     $Post = new TestPost();
     $Post->Author->validate = array('user' => array('rule' => array('notBlank')));
     // If validation error occurs, rollback() should be called.
     $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
     $db->expects($this->once())->method('begin')->will($this->returnValue(true));
     $db->expects($this->never())->method('commit');
     $db->expects($this->once())->method('rollback');
     $Post->setDataSourceObject($db);
     $Post->Author->setDataSourceObject($db);
     $data = array('Post' => array('title' => 'New post', 'body' => 'Content', 'published' => 'Y'), 'Author' => array('user' => '', 'password' => "sekret"));
     $Post->saveAll($data, array('validate' => true));
     // If exception thrown, rollback() should be called too.
     $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
     $db->expects($this->once())->method('begin')->will($this->returnValue(true));
     $db->expects($this->never())->method('commit');
     $db->expects($this->once())->method('rollback');
     $Post->setDataSourceObject($db);
     $Post->Author->setDataSourceObject($db);
     $data = array('Post' => array('title' => 'New post', 'body' => $db->expression('PDO_EXCEPTION()'), 'published' => 'Y'), 'Author' => array('user' => 'New user', 'password' => "sekret"));
     try {
         $Post->saveAll($data, array('validate' => true));
         $this->fail('No exception thrown');
     } catch (PDOException $e) {
     }
     // Otherwise, commit() should be called.
     $db = $this->_getMockDboSource(array('begin', 'commit', 'rollback'));
     $db->expects($this->once())->method('begin')->will($this->returnValue(true));
     $db->expects($this->once())->method('commit');
     $db->expects($this->never())->method('rollback');
     $Post->setDataSourceObject($db);
     $Post->Author->setDataSourceObject($db);
     $data = array('Post' => array('title' => 'New post', 'body' => 'Content', 'published' => 'Y'), 'Author' => array('user' => 'New user', 'password' => "sekret"));
     $Post->saveAll($data, array('validate' => true));
 }
Esempio n. 2
0
 /**
  * test saveAll with transactions and ensure there is no missing rollback.
  *
  * @return void
  */
 public function testSaveAllAssociatedTransactionNoRollback()
 {
     $testDb = ConnectionManager::getDataSource('test');
     $db = $this->getMock('DboSource', array('connect', 'rollback', 'describe', 'create', 'update', 'begin'));
     $db->columns = $testDb->columns;
     $db->expects($this->once())->method('rollback');
     $db->expects($this->any())->method('describe')->will($this->returnValue(array('id' => array('type' => 'integer', 'length' => 11), 'title' => array('type' => 'string'), 'body' => array('type' => 'text'), 'published' => array('type' => 'string'))));
     $Post = new TestPost();
     $Post->setDataSourceObject($db);
     $Post->Author->setDataSourceObject($db);
     $Post->Author->validate = array('user' => array('rule' => array('notEmpty')));
     $data = array('Post' => array('title' => 'New post', 'body' => 'Content', 'published' => 'Y'), 'Author' => array('user' => '', 'password' => "sekret"));
     $Post->saveAll($data, array('validate' => true));
 }