コード例 #1
0
 /**
  * Tests to ensure that the Query Mocker is used to execute a query.
  */
 public function testExecuteMocker()
 {
     $mocker = new QueryMocker();
     $mocker->setResult(true);
     QueryType::setMocker($mocker);
     $this->assertInstanceOf('\\Queryer\\Mock\\QueryMockerResult', $this->queryType->execute());
 }
コード例 #2
0
 /**
  * Tests the setResult method to ensure that it always returns the same result each time a query is executed.
  */
 public function testSetResult()
 {
     $resultSet = array(array('user_id' => 1, 'user_name' => 'Me'), array('user_id' => 2, 'user_name' => 'You'));
     $affectedRows = 2;
     $insertId = 100;
     $errorCode = 504;
     $errorMessage = 'error!';
     // Set our result.
     $this->queryMocker->setResult($resultSet, $affectedRows, $insertId, $errorCode, $errorMessage);
     // Just get the result.
     $result = $this->queryMocker->execute(array());
     // Make sure we get an instance of a QueryMockerResult.
     $this->assertInstanceOf('\\Queryer\\Mock\\QueryMockerResult', $result);
     $this->assertEquals(count($resultSet), $result->getNumRows());
     $this->assertEquals($affectedRows, $result->getAffectedRows());
     $this->assertEquals($insertId, $result->getInsertId());
     $this->assertEquals($errorCode, $result->getErrorCode());
     $this->assertEquals($errorMessage, $result->getErrorMessage());
     // Check the rows.
     for ($i = 0; $i < count($resultSet); $i++) {
         $row = $resultSet[$i];
         $this->assertEquals($row, $result->fetchAssoc());
     }
 }