1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace App \Tests \Controller ;
6
+
7
+ use App \Entity \User ;
8
+ use Doctrine \ORM \EntityManagerInterface ;
9
+ use Symfony \Bundle \FrameworkBundle \KernelBrowser ;
10
+ use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
11
+ use Zenstruck \Foundry \Test \ResetDatabase ;
12
+
13
+ class ProfileControllerTest extends WebTestCase
14
+ {
15
+ use ResetDatabase;
16
+
17
+ private KernelBrowser $ client ;
18
+ private User $ user ;
19
+
20
+ protected function setUp (): void
21
+ {
22
+ parent ::setUp ();
23
+
24
+ $ this ->user = new User ();
25
+ $ this ->
user ->
setEmail (
'[email protected] ' );
26
+ $ this ->user ->setPassword ('test ' );
27
+ $ this ->user ->setRoles (['ROLE_USER ' ]);
28
+
29
+ $ this ->client = static ::createClient ();
30
+ $ em = $ this ->client ->getContainer ()->get (EntityManagerInterface::class);
31
+ $ em ->persist ($ this ->user );
32
+ $ em ->flush ();
33
+ }
34
+
35
+ public function test (): void
36
+ {
37
+ $ this ->client ->loginUser ($ this ->user );
38
+ $ crawler = $ this ->client ->request ('GET ' , '/profile ' );
39
+ $ this ->assertTrue ($ this ->client ->getResponse ()->isOk ());
40
+ $ this ->
assertTrue (
$ crawler->
filter (
'body:contains("[email protected] ") ' )->
count () ===
1 );
41
+ }
42
+
43
+ public function testNotAuthenticated (): void
44
+ {
45
+ $ this ->client ->request ('GET ' , '/profile ' );
46
+ $ this ->assertEquals (401 , $ this ->client ->getResponse ()->getStatusCode ());
47
+ }
48
+ }
0 commit comments