私はZend Framework 2 Documentationのアルバムの例を使用してアプリケーションを作成しました。Zend Framework 2 phpunit joinでテーブルをテストする
phpunit
を使用してunittestingしていますが、テーブルAccount_Type
とjoin
のテーブルをテストしているときに問題が発生しています。
ここにそのコードを示します。
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;
}
ユニットテストコードがあります。
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());
}
私は、このエラーtestFetchAllReturnsAllAlbums
方法でこのライン$this->assertSame($resultSet, $albumTable->fetchAll());
ため
Argument 1 passed to Zend\Db\Sql\Sql::__construct() must be an instance of
Zend\Db\Adapter\Adapter, null given,
をエラーを取得しています。
誰かが参加のためのphpunitテストを行っている場合は、その例を挙げてください。
あなたのモックオブジェクトで '$ this-> tableGateway-> getAdapter()'を呼び出して、NULLを返します。 'Zend \ Db \ Sql \ Sql'は' Zend \ Db \ Adapter \ Adapter'のインスタンスを期待しています。 。私はモックオブジェクトにはまだ慣れていませんが、 'TableGateway'で' select'メソッドを嘲笑しているわけではありませんが、 'AlbumTable'では' Sql'オブジェクトで 'select'メソッドを呼び出していますか? – Andy0708