2012-10-22 88 views
0

我正在嘗試按照在線ZF2教程在Zf2專輯模塊phpunit。以下是調試信息。與ZF2相冊模塊Phpunit測試連接到AlbumTable時失敗

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); 

其中要求在專輯\型號如下functon \ AlbumTable :: __construct()

public function __construct(Adapter $adapter) 
    { 
     $this->adapter = $adapter; 
     $this->resultSetPrototype = new ResultSet(); 
     $this->resultSetPrototype->setArrayObjectPrototype(new Album()); 
     $this->initialize(); 
    } 

任何幫助結束這個失敗的測試非常感謝。

回答

0

把它解決了。我碰巧看到Zend Framework2教程中給出的Album模塊已經改變。我再次跟着它來糾正已更改的代碼。現在提到的問題已經被整理出來。