assume, i have a method in AlbumTable class like the following :
/////////
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);
}
/////////
The question is how to test that method ? I have created test case like the
following :
namespace AlbumTest\Model;
use Album\Model\AlbumTable;
use Album\Model\Album;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Sql;
use PHPUnit_Framework_TestCase;
class AlbumTableTest extends PHPUnit_Framework_TestCase
{
public function testFetchAllReturnsAllAlbums()
{
$resultSet = new ResultSet();
$mockTableGateway =
$this->getMock('Zend\Db\TableGateway\TableGateway',
array('select'), array(), '',
false);
$mockTableGateway->expects($this->once())
->method('select')
->will($this->returnValue($resultSet));
$albumTable = new AlbumTable($mockTableGateway);
$albumTable->fetchAll();
$this->assertSame($resultSet, $albumTable->fetchAll());
}
}
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/How-to-test-complex-Query-in-ZF2-using-phpunit-tp4659268.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]