I'm new with php unit and Zend 2.
I need to write unit test for the function below:
public function getMyList($limitDay)
{
// build time
$limitTime = strtotime("-".$limitDay." day"); // UNIX timestamp
$timeStr = date("Y-m-d h:i:s", $limitTime); // format time
// run query
$resultSet = $this->tableGateway->select(
// use closure
function (Select $select) use ($timeStr) {
$condition = function (Where $where) use($timeStr) {
$where->greaterThan('SEND_TIME', new Expression('TIMESTAMP \''.$timeStr.'\''));
};
$select->where($condition);
}
);
return $resultSet;
}
As ZF2 document for unit test, I can create a unit test function like this:
public function testGetMyList()
{
$resultSet = new ResultSet();
$mockTableGateway = $this->getMock('Zend\Db\TableGateway\TableGateway',
array('select'), array(), '', false);
$mockTableGateway->expects($this->once())
->method('select')
->with(/*[argument]*/)
->will($this->returnValue($resultSet));
$albumTable = new AlbumTable($mockTableGateway);
$this->assertSame($resultSet, $albumTable->getMyList(1));
}
But I don't know how to describe Closure
function (Select $select) use ($timeStr) {
$condition = function (Where $where) use($timeStr) {
$where->greaterThan('SEND_TIME', new Expression('TIMESTAMP \''.$timeStr.'\''));
};
$select->where($condition);
}
for
/*[argument]*/
There's no tutorial for describe it or create mock for Closure.
Please help me in this case! Thank you