Zend Framework 2 Documentation'dan Album örneğini kullandım ve bir uygulama oluşturdum.Zend Framework 2 phpunit bir tabloyu birleştirme ile sınama
Şimdi phpunit
kullanarak test ederken, join
tablosunu kullanarak tablo Account_Type
tablosunu kullanarak bir sorun yaşıyorum.
İşte bunun için kod.
fetchAll
fonksiyonu yukarıda tablo
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;
}
Birim test kodu olmasıdır.
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());
}
ben testFetchAllReturnsAllAlbums
yönteminde bu hat $this->assertSame($resultSet, $albumTable->fetchAll());
için hatayı bu hatayı
Argument 1 passed to Zend\Db\Sql\Sql::__construct() must be an instance of
Zend\Db\Adapter\Adapter, null given,
alıyorum.
Herhangi biri birleştirme için phpunit testi yaptıysa, lütfen bunun için bir örnek sağlayın.
Sahte nesnesine '$ this-> tableGateway-> getAdapter()' diyerek, NULL değerini döndürür ve 'Zend \ Db \ Sql \ Sql', 'Zend \ Db \ Adapter \ Adapter' örneğini bekler. . Henüz sahte nesnelerle çok aşina değilim ama 'TableGateway' üzerinde' select' yöntem alay edilmez, ancak 'AlbumTable', sense nesne Sql' üzerinde' select' yöntemini diyorsun? – Andy0708