Slide 38
Slide 38 text
HOW DO YOU TEST THIS?
class BarTest extends PHPUnit_Framework_Testcase
{
! public function testGetBazById()
! {
! ! $bazId = 666;
! ! $expectedResults= array(1, 2, 3, 4, 5);
! ! $mockDb = $this->getMockBuilder('\Grumpy\Db')
! ! ! ->disableOriginalConstructor()
! ! ! ->setMethods(array('query', 'execute', 'bind'))
! ! ! ->getMock();
! ! $mockDb->expects($this->once())
! ! ! ->method('query');
! ! $mockDb->expects($this->once())
! ! ! ->method('bind');
! ! $mockDb->expects($this->once())
! ! ! ->method('execute')
! ! ! ->will($this->returnValue($testResults));
! ! $testBar = new Bar();
! ! $testBar->setDb($mockDb);
! ! $testResults = $testBar->getBazById($bazId);
! ! $this->assertEquals(
! ! ! $expectedResults,
! ! ! $testResults,
! ! ! 'Did not get expected baz result set'
! ! );
! }
}