Bonjour.
J'essaye d'utiliser les test unitaires avec PHPUnit et ZendFramework. Cependant lorsque je veut tester mon fichier avec la commande
>phpunit EntitesTest
Le message suivant apparait :
Je vous joint les fichiers en question :Fatal error: class 'Zend_Db_Table' not found in '.../entites.php' line 3.
Mon fichier EntitesTest.php qui se situe dans MonApp/tests/application/models/
Mon models entites.php qui se situe dans MonApp/application/models/
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
33
34
35
36
37
38
39
40
41
42
43
44
45 <?php require_once 'PHPUnit/Framework/TestCase.php'; require dirname(dirname(dirname(dirname(__FILE__)))).'\application\models\DbTable\Entites.php'; class EntitesTest extends PHPUnit_Framework_TestCase { private $_entite; public function setUp() { $this->_entite = new Model_DbTable_Entites(); } public function tearDown() { /* Tear Down Routine */ } public function testConstructeur() { $this->assertTrue(isset($this->_entite)); } public function testCrud() { $nb1 = $this->_entite->fetchAll()->count(); $this->_entite->ajouterEntite('xxxx'); $nb2 = $this->_entite->fetchAll()->count(); $this->assertTrue($nb2-$nb1=1); $id = $this->_entite->fetchAll('select Id_Entite from entite where Nom_Entite = \'xxxx\''); $obj = $this->_entite->getEntite($id); $this->assertTrue($obj[Nom_Entite]='xxxx'); if(($this->assertEqual($obj[Nom_Entite],'xxxx'))==true){ $this->_entite->editerEntite($id,'yyyy'); $obj = $this->_entite->getEntite($id); $this->assertEqual($obj[Nom_Entite],'yyyy'); $this->_entite->supprimerEntite($id); $nb3 = $this->_entite->fetchAll()->count(); $this->assertEqual($nb1,$nb3); } } }
Je me doute qu'il ne trouve pas ma classe. Mais je me demande surtout pourquoi etant donner qu'en temps normal grace a l'autoloader il la trouve ...
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 <?php class Model_DbTable_Entites extends Zend_Db_Table { protected $_name = 'entites'; public function getEntite($id){ $row = $this->fetchRow('Id_Entite = ' . (int)$id); if(!$row){ throw new Exception("Ligne $id non trouvée"); } return $row->toArray(); } public function ajouterEntite($nom){ $data = array('Nom_Entite' => $nom); $this->insert($data); } public function editerEntite($id, $nom){ $data = array('Nom_Entite' => $nom); $this->update($data, 'Id_Entite = ' . (int)$id); } public function supprimerEntite($id){ $this->delete('Id_Entite = ' . (int)$id); } }
Partager