Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unit Test select Join Zend\Db
<?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
You can’t perform that action at this time.