Skip to content

Instantly share code, notes, and snippets.

@bakura10
Created February 25, 2013 21:00
Show Gist options
  • Save bakura10/5033253 to your computer and use it in GitHub Desktop.
Save bakura10/5033253 to your computer and use it in GitHub Desktop.
<?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);
}
class AlbumTableTest extends PHPUnit_Framework_TestCase
{
public function testFetchAllReturnsAllAlbums()
{
$resultSet = new ResultSet();
$mockTableGateway = $this->getMock('Zend\Db\TableGateway\TableGateway',
array('select', 'getSql'), array(), '', false);
$sqlMock = $this->getMock('Zend\Db\Sql\Sql', array('select'), array(), '', false);
$mockTableGateway->expects($this->once())
->method('getSql')
->will($this->returnValue($sqlMock));
$select = $this->getMock('Zend\Db\Sql\Select', array('columns'), array(), '', false);
// ... blablabla
$mockTableGateway->expects($this->once())
->method('select')
->will($this->returnValue($resultSet));
$albumTable = new AlbumTable($mockTableGateway);
$albumTable->fetchAll();
$this->assertSame($resultSet, $albumTable->fetchAll());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment