I have used Album example from Zend Framework 2 Documentation and created a application.
Now while unittesting it using phpunit I am having an issue while testing a table which is having a join with say table Account_Type.
Here is the code for it.
fetchAll function is 
function fetachAll()
{
    $sql = new Sql($this->tableGateway->getAdapter());
    $select = $sql->select();
    $select->from('Album')
           ->columns(array('id', 'name', 'account_type_id', 'managing_account_id'))
       ->join(array('AT' => 'account_type'), 'album.account_type_id = AT.account_type_id');
    $resultSet = $this->tableGateway->selectWith($select);
    return $resultSet; 
}
Unit test code for above table is.
public function testFetchAllReturnsAllAlbums()
{
    $resultSet= new ResultSet();
    $mockTableGateway = $this->getMock(
        'Zend\Db\TableGateway\TableGateway', 
        array('select'), 
        array(), 
        '', 
        false
    );    
    $mockTableGateway->expects($this->once())
                     ->method('select')
                     ->with()
                     ->will($this->returnValue($resultSet));
    $albumTable = new AlbumTable($mockTableGateway);
    $this->assertSame($resultSet, $albumTable->fetchAll());
}
I am getting error this error
Argument 1 passed to Zend\Db\Sql\Sql::__construct() must be an instance of
Zend\Db\Adapter\Adapter, null given,
for this line $this->assertSame($resultSet, $albumTable->fetchAll()); in testFetchAllReturnsAllAlbums method.
If any one have done phpunit testing for join, please provide an example for the same.
You might want to mock the getAdapter method of your Zend\Db\TableGateway\TableGateway object. This method is called and its returned value passed to the Zend\Db\Sql\Sql constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With