Bonjour,
pour mes études, nous couvrons un module de tests unitaire et fonctionnels mais je em retrouve bloqué par trois de mes tests dont je ne comprends pas l'origine de l'erreur.
Le message d'erreur:
Mon fichier de test "HomeControllerTest.php":bin/phpunit tests/Controller/HomeControllerTest.php --coverage-html coverage/
PHP Warning: Module 'mysqli' already loaded in Unknown on line 0
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
Testing App\Test\Controller\HomeControllerTest
.....F..F.F. 12 / 12 (100%)
Time: 3.85 seconds, Memory: 34.00 MB
There were 3 failures:
1) App\Test\Controller\HomeControllerTest::testExistLinkToDeconnexionIfLoggedIn
Failed asserting that the Crawler matches selector "a[href='/logout/']".
/home/quentin/Dev/TestUnit/covoiturage/vendor/symfony/framework-bundle/Test/DomCrawlerAssertionsTrait.php:28
/home/quentin/Dev/TestUnit/covoiturage/tests/Controller/HomeControllerTest.php:73
2) App\Test\Controller\HomeControllerTest::testExistLinkToNouveauTrajetIfLoggedIn
Failed asserting that the Crawler matches selector "a[href='/trajet/new']".
/home/quentin/Dev/TestUnit/covoiturage/vendor/symfony/framework-bundle/Test/DomCrawlerAssertionsTrait.php:28
/home/quentin/Dev/TestUnit/covoiturage/tests/Controller/HomeControllerTest.php:104
3) App\Test\Controller\HomeControllerTest::testExistLinkToMesTrajetsIfLoggedIn
Failed asserting that the Crawler matches selector "a[href='/trajet/']".
/home/quentin/Dev/TestUnit/covoiturage/vendor/symfony/framework-bundle/Test/DomCrawlerAssertionsTrait.php:28
/home/quentin/Dev/TestUnit/covoiturage/tests/Controller/HomeControllerTest.php:126
FAILURES!
Tests: 12, Assertions: 12, Failures: 3.
Generating code coverage report in HTML format ... done
Code php : 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137 <?php namespace App\Test\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class HomeControllerTest extends WebTestCase { // Home page public function testLinkToHomePageWorking() { $client = self::createClient(); $client->request("GET", "/"); $this->assertResponseIsSuccessful(); } // Inscription public function testExistLinkToInscriptionIfLoggedOut() { $client = self::createClient(); $client->request("GET", "/"); $this->assertSelectorExists("a[href='/register']"); } public function testNotExistLinkToInscriptionIfLoggedIn() { $loggedClient = self::createClient([], [ 'PHP_AUTH_USER' => 'quentin@mail.fr', 'PHP_AUTH_PW' => 'quentin' ]); $loggedClient->request("GET", "/"); $this->assertSelectorNotExists('a[href="/register"]'); } // Connexion public function testExistLinkToConnexionIfLoggedOut() { $client = self::createClient(); $client->request("GET", "/"); $this->assertSelectorExists("a[href='/login']"); } public function testNotExistLinkToConnexionIfLoggedIn() { $loggedClient = self::createClient([], [ 'PHP_AUTH_USER' => 'quentin@mail.fr', 'PHP_AUTH_PW' => 'quentin' ]); $loggedClient->request("GET", "/"); $this->assertSelectorNotExists("a[href='/login']"); } // Deconnexion public function testExistLinkToDeconnexionIfLoggedIn() { $loggedClient = self::createClient([], [ 'PHP_AUTH_USER' => 'quentin@mail.fr', 'PHP_AUTH_PW' => 'quentin' ]); $loggedClient->request("GET", "/"); $this->assertSelectorExists("a[href='/logout']"); } public function testNotExistsLinkToDeconnexionIfLoggedOut() { $client = self::createClient(); $client->request("GET", "/"); $this->assertSelectorNotExists("a[href='/logout']"); } // Recherche trajet public function testExistLinkToRechercheTrajet() { $client = self::createClient(); $client->request("GET", "/"); $this->assertSelectorExists("a[href='/trajet/search']"); } // Nouveau trajet public function testExistLinkToNouveauTrajetIfLoggedIn() { $loggedClient = self::createClient([], [ 'PHP_AUTH_USER' => 'quentin@mail.fr', 'PHP_AUTH_PW' => 'quentin' ]); $loggedClient->request("GET", "/"); $this->assertSelectorExists("a[href='/trajet/new']"); } public function testNotExistsLinkToNouveauTrajetIfLoggedOut() { $client = self::createClient(); $client->request("GET", "/"); $this->assertSelectorNotExists("a[href='/trajet/new']"); } // Mes trajets public function testExistLinkToMesTrajetsIfLoggedIn() { $loggedClient = self::createClient([], [ 'PHP_AUTH_USER' => 'quentin@mail.fr', 'PHP_AUTH_PW' => 'quentin' ]); $loggedClient->request("GET", "/"); $this->assertSelectorExists("a[href='/trajet/']"); } public function testNotExistsLinkToMesTrajetsIfLoggedOut() { $client = self::createClient(); $client->request("GET", "/"); $this->assertSelectorNotExists("a[href='/trajet/']"); } }
Le code source de ma page web quand je suis connecté:
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Accueil</title> </head> <body> <h1>Accueil</h1> <a href="/trajet/new"><button>Nouveau trajet</button></a> <a href="/trajet/"><button>Mes trajets</button></a> <a href="/logout"><button>Déconnexion</button></a> <a href="/trajet/search"><button>Rechercher un trajet</button></a>
Le code source quand je suis déconnecté:
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Accueil</title> </head> <body> <h1>Accueil</h1> <a href="/login"><button>Se connecter</button></a> <a href="/register"><button>S'inscrire</button></a> <a href="/trajet/search"><button>Rechercher un trajet</button></a>
Ce que je ne comprends pas, c'est que je test deux fois chaque route et qu'une fois sur deux il n'y a pas d'erreur. Je met également un lien vers le github de ce projet si vous désirez en voir plus: https://github.com/BlueSkunka/covoiturageDTD
Merci d'avance de l'aide que vous m'apporterez!
Partager