use*_*996 6 php phpunit zend-framework2
我使用了Zend Framework 2 Documentation中的Album示例并创建了一个应用程序.
现在,在使用单元测试它phpunit,我有一个问题,而测试它有一个表join与表说Account_Type.
这是它的代码.
fetchAll 功能是
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;
}
Run Code Online (Sandbox Code Playgroud)
上表的单元测试代码是.
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());
}
Run Code Online (Sandbox Code Playgroud)
我收到错误此错误
Argument 1 passed to Zend\Db\Sql\Sql::__construct() must be an instance of
Zend\Db\Adapter\Adapter, null given,
Run Code Online (Sandbox Code Playgroud)
此行$this->assertSame($resultSet, $albumTable->fetchAll());中testFetchAllReturnsAllAlbums的方法.
如果有人为加入做了phpunit测试,请提供相同的示例.
您可能想模拟对象getAdapter的方法Zend\Db\TableGateway\TableGateway。调用此方法并将其返回值传递给Zend\Db\Sql\Sql构造函数。
| 归档时间: |
|
| 查看次数: |
1153 次 |
| 最近记录: |