Here is a function which uses Zend DB / Tablegateway :
public function listAttestations($sSidx = null, $sSord = null, $iOffset = 0, $iLimit = 0)
{
try {
$resultSet = $this->tableGateway->select(
function (Select $select) use ($sSidx, $sSord, $iOffset, $iLimit) {
if ($sSidx != null && $sSord != null) {
$select->order($sSidx.' '.$sSord);
}
$select->join(
'f_travclient',
'syndic_client_id = f_travclient.travClient_id',
array('syndic' => 'nom')
);
$select->offset($iOffset);
$select->limit($iLimit);
}
);
return $resultSet;
} catch (\Exception $e) {
throw new \Exception($e);
}
}
I use PHPUnit to do unit tests. Perhaps, I don't know how to make the function which crosses my previous method. I thought this could be functional :
public function testListAttestations()
{
$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));
$attestTable = new FMaiAttestationTable($mockTableGateway, $this->adapter, $this->sql);
$this->assertSame($resultSet, $attestTable->listAttestations('maiAttestation_id', 'ASC', 0, 30));
}
But this doesn't go further the :
function (Select $select) use ($sSidx, $sSord, $iOffset, $iLimit) {
Could somebody help me ? Thanks.