Bonjour, j'ai un souci avec PHPUnit
Voici ma fonction, un count tout bête :
Et mon test, que j'ai remanié dans tous les sens :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 public function countAtt() { try { $sql = new Sql($this->adapter); $select = new Select(); $select->from('table1'); $select->join('table2', 'join1 = table2.join2', array('syndic' => 'nom')); $select->columns(array('num' => new \Zend\Db\Sql\Expression('COUNT(*)'))); $statement = $sql->prepareStatementForSqlObject($select); $result = $statement->execute(); $num = $result->current(); return $num["num"]; } catch (\Exception $e) { throw new \Exception($e); } }
Bon, le test est pas peaufiné puisqu'il fait juste un select mais ça aurait été une erreur normale.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 public function testCountAttReturnsNumberOfAtt() { $resultSet = new ResultSet(); $mockDriver = $this->getMockBuilder('Zend\Db\Adapter\Driver\DriverInterface')->getMock(); $mockAdapter = $this->getMockBuilder('Zend\Db\Adapter\AdapterInterface') ->setConstructorArgs(array($mockDriver)) ->getMock(); $mockSql = $this->getMockBuilder('Zend\Db\Sql\Sql') ->setConstructorArgs(array($mockAdapter)) ->getMock(); $mockTableGateway = $this->getMock('Zend\Db\TableGateway\TableGateway', array('getSql', 'select'), array(), '', false); $mockTableGateway->expects($this->once()) ->method('select') ->with() ->will($this->returnValue($mockSql)); $mockTableGateway->expects($this->once()) ->method('select') ->with($mockSql) ->will($this->returnValue($resultSet)); $attTable = new AttTable($mockTableGateway); $this->assertSame($resultSet, $attTable->countAtt()); }
Là, j'ai cette fichue erreur :
Exception: Argument 1 passed to Zend\Db\Sql\Sql::__construct() must implement in
terface Zend\Db\Adapter\AdapterInterface, null given, called in (chemin du script) on
line 40 and defined
Je sais pas comment mocker ce fichu AdapterInterface :s est-ce que quelqu'un pourrait m'aider svp ? :s
Partager