连接到AlbumTable时,使用ZF2相册模块的Phpunit测试失败

时间:2012-10-22 11:22:12

标签: phpunit zend-framework2

我正在按照在线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();
    }

非常感谢任何有关此失败测试的帮助。

1 个答案:

答案 0 :(得分:0)

解决了。我碰巧看到Zend Framework2教程中给出的Album模块已被更改。我再次跟着它来纠正改变的代码。现在提到的问题已经解决了。

相关问题