-
-
Save samsonasik/5048353 to your computer and use it in GitHub Desktop.
Unit Test select Join Zend\Db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assume, i have a method in AlbumTable class like the following : | |
<?php | |
///////// | |
public function fetchAll() | |
{ | |
$sqlSelect = $this->tableGateway->getSql() | |
->select()->columns(array('artist', 'title', 'id')) | |
->join('track', 'track.album_id = album.id', array(), 'left'); | |
return $this->tableGateway->select($sqlSelect); | |
} | |
///////// | |
?> | |
<?php | |
public function testFetchAllReturnsAllAlbums() | |
{ | |
$resultSet = new ResultSet(); | |
$mockSelect = $this->getMock('Zend\Db\Sql\Select', array('columns', 'join'), array(), '', false); | |
$mockSelect->expects($this->once()) | |
->method('columns') | |
->with(array('artist', 'title', 'id')) | |
->will($this->returnValue($mockSelect)); | |
$mockSelect->expects($this->once()) | |
->method('join') | |
->with('track', 'track.album_id = album.id', array(), 'left') | |
->will($this->returnValue($mockSelect)); | |
$mockSql = $this->getMock('Zend\Db\Sql\Sql', array('select'), array(), '', false); | |
$mockSql->expects($this->once()) | |
->method('select') | |
->with() | |
->will($this->returnValue($mockSelect)); | |
$mockTableGateway = $this->getMock('Zend\Db\TableGateway\TableGateway', | |
array('getSql', 'select'), array(), '', false); | |
$mockTableGateway->expects($this->once()) | |
->method('getSql') | |
->with() | |
->will($this->returnValue($mockSql)); | |
$mockTableGateway->expects($this->once()) | |
->method('select') | |
->with($mockSelect) | |
->will($this->returnValue($resultSet)); | |
$albumTable = new AlbumTable($mockTableGateway); | |
$this->assertSame($resultSet, $albumTable->fetchAll()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment