Commit 5c7dcdc 1 parent 019b721 commit 5c7dcdc Copy full SHA for 5c7dcdc
File tree 4 files changed +86
-3
lines changed
4 files changed +86
-3
lines changed Original file line number Diff line number Diff line change @@ -232,10 +232,41 @@ class PhpFunctionType extends AbstractType
232
232
}
233
233
```
234
234
235
- ### Création d'un contrôleur pour ` PhpFunction `
235
+ ### Création d'un contrôleur pour ` Homepage `
236
236
237
237
``` bash
238
238
php bin/console make:controller
239
- > PhpFunctionController
240
- > annotation
239
+ > HomepageController
240
+ > PHPUnit tests? yes
241
+ ```
242
+
243
+ 3 fichiers sont créés :
244
+
245
+ on modifie le fichier ` src/Controller/HomepageController.php ` :
246
+
247
+ ``` php
248
+ # src/Controller/HomepageController.php
249
+ #...
250
+ #[Route('/', name: 'homepage')]
251
+ public function index(): Response
252
+ {
253
+ return $this->render('homepage/index.html.twig', [
254
+ 'controller_name' => 'HomepageController',
255
+ ]);
256
+ }
257
+ #...
258
+ ```
259
+
260
+ et son test unitaire ` tests/Controller/HomepageControllerTest.php ` :
261
+
262
+ ``` php
263
+ # tests/Controller/HomepageControllerTest.php
264
+ #...
265
+ public function testSomething(): void
266
+ {
267
+ $client = static::createClient();
268
+ $client->request('GET', '/');
269
+ self::assertResponseIsSuccessful();
270
+ }
271
+ #...
241
272
```
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Controller ;
4
+
5
+ use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
6
+ use Symfony \Component \HttpFoundation \Response ;
7
+ use Symfony \Component \Routing \Attribute \Route ;
8
+
9
+ final class HomepageController extends AbstractController{
10
+ #[Route('/ ' , name: 'homepage ' )]
11
+ public function index (): Response
12
+ {
13
+ return $ this ->render ('homepage/index.html.twig ' , [
14
+ 'controller_name ' => 'HomepageController ' ,
15
+ ]);
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ {% extends ' base.html.twig' %}
2
+
3
+ {% block title %}Hello HomepageController!{% endblock %}
4
+
5
+ {% block body %}
6
+ <style >
7
+ .example-wrapper { margin : 1em auto ; max-width : 800px ; width : 95% ; font : 18px /1.5 sans-serif ; }
8
+ .example-wrapper code { background : #F5F5F5 ; padding : 2px 6px ; }
9
+ </style >
10
+
11
+ <div class =" example-wrapper" >
12
+ <h1 >Hello {{ controller_name }}! ✅</h1 >
13
+
14
+ This friendly message is coming from:
15
+ <ul >
16
+ <li >Your controller at <code >E:/SITES/2025/function-php8/src/Controller/HomepageController.php</code ></li >
17
+ <li >Your template at <code >E:/SITES/2025/function-php8/templates/homepage/index.html.twig</code ></li >
18
+ </ul >
19
+ </div >
20
+ {% endblock %}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace App \Tests \Controller ;
4
+
5
+ use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
6
+
7
+ final class HomepageControllerTest extends WebTestCase{
8
+ public function testIndex (): void
9
+ {
10
+ $ client = static ::createClient ();
11
+ $ client ->request ('GET ' , '/ ' );
12
+
13
+ self ::assertResponseIsSuccessful ();
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments