示例#1
0
 public function testGetRecordByID()
 {
     //Query Stubbing
     $queryStub = $this->getMock('MockPdoStatement', array('execute', 'fetch'));
     $queryStub->expects($this->once())->method('execute')->will($this->returnSelf());
     $queryStub->expects($this->once())->method('fetch')->will($this->returnValue(array('id' => 1, 'username' => 'baptiste')));
     //PDO stubbing
     $pdoStub = $this->getMock('\\RjakesTest\\FmPdo\\MockPdo', array('prepare'));
     $pdoStub->expects($this->once())->method('prepare')->with($this->equalTo("SELECT * FROM users WHERE id='1' LIMIT 1;"))->will($this->returnValue($queryStub));
     $this->fmPdo->setConnection($pdoStub);
     $this->assertInstanceOf('\\Rjakes\\FmPdo\\Record', $this->fmPdo->getRecordByID('users', 1));
 }
示例#2
0
 public function testFindConstruct()
 {
     //Query Stubbing
     $queryStub = $this->getMock('\\RjakesTest\\FmPdo\\MockPdoStatement', array('execute', 'fetchAll'));
     $queryStub->expects($this->once())->method('execute')->will($this->returnSelf());
     $queryStub->expects($this->any())->method('fetchAll')->will($this->returnValue(array(array('id' => 1, 'username' => 'baptiste'))));
     //PDO stubbing
     $pdoStub = $this->getMock('\\RjakesTest\\FmPdo\\MockPdo', array('prepare'));
     $pdoStub->expects($this->once())->method('prepare')->with($this->equalTo("SELECT * FROM users WHERE username=:username  ;"))->will($this->returnValue($queryStub));
     $this->fmPdo->setConnection($pdoStub);
     $findC = new Find('users', $this->fmPdo);
     $findC->addFindCriterion('username', 'baptiste');
     $resultSet = $findC->execute();
     $this->assertInstanceOf('\\Rjakes\\FmPdo\\Result', $resultSet);
     /** @var Record $record */
     $record = $resultSet->getFirstRecord();
     $this->assertInstanceOf('\\Rjakes\\FmPdo\\Record', $record);
     $this->assertEquals('baptiste', $record->getField('username'));
     $this->assertEquals('1', $record->getField('id'));
 }