में शामिल होने वाली तालिका का परीक्षण करने के लिए मैंने ज़ेंड फ्रेमवर्क 2 दस्तावेज़ीकरण से एल्बम उदाहरण का उपयोग किया है और एक एप्लिकेशन बनाया है।ज़ेंड फ्रेमवर्क 2 phpunit
अब phpunit
का उपयोग करके इसे बेकार करते समय मुझे एक तालिका का परीक्षण करते समय कोई समस्या है जिसमें join
है जिसमें तालिका Account_Type
है।
यहां इसके लिए कोड है।
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() 'को कॉल कर रहे हैं, जो पूर्ण लौटाता है, और' ज़ेंड \ डीबी \ एसक्यूएल \ एसक्यूएल '' ज़ेंड \ डीबी \ एडाप्टर \ एडाप्टर 'के उदाहरण की अपेक्षा करता है । मैं अभी तक नकली वस्तुओं से परिचित नहीं हूं, लेकिन क्या आप 'टेबलगेटवे' पर 'चयन' विधि का मज़ाक उड़ा रहे हैं, लेकिन आपके 'एल्बमटेबल' में, आप 'एसक्यूएल' ऑब्जेक्ट पर 'चयन' विधि को कॉल कर रहे हैं? – Andy0708