Esempio n. 1
0
 public function getSetNumber()
 {
     $post = new TestPost();
     $this->assertEmpty($post->getNumber());
     $post->setNumber(5);
     $this->assertEquals(5, $post->getNumber());
 }
Esempio n. 2
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. 3
0
 /**
  * test saveAssociated with transactions and ensure there is no missing rollback.
  *
  * @return void
  */
 public function testSaveAssociatedTransactionNoRollback()
 {
     $testDb = ConnectionManager::getDataSource('test');
     $db = $this->getMock('DboSource', array('connect', 'rollback', 'describe', 'create', '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->saveAssociated($data, array('validate' => true, 'atomic' => true));
 }