我正在按照在线ZF2教程尝试Zf2相册模块中的phpunit。以下是调试信息。
Album\Model\AlbumTableTest::testFetchAllReturnsAllAlbums
Argument 1 passed to Album\Model\AlbumTable::__construct() must be an instance of Zend\Db\Adapter\Adapter, instance of Mock_TableGateway_fb3537df given, called in D:\www\zend2\tests\module\Album\src\Album\Model\AlbumTableTest.php on line 26 and defined
使用的功能是
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());
}
调试信息中提到的第26行是
$albumTable = new AlbumTable($mockTableGateway);
在Album \ Model \ AlbumTable :: __ construct()
中调用以下功能public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
$this->resultSetPrototype = new ResultSet();
$this->resultSetPrototype->setArrayObjectPrototype(new Album());
$this->initialize();
}
非常感谢任何有关此失败测试的帮助。
答案 0 :(得分:0)
解决了。我碰巧看到Zend Framework2教程中给出的Album模块已被更改。我再次跟着它来纠正改变的代码。现在提到的问题已经解决了。