3
3
namespace App \Tests \Functional ;
4
4
5
5
use App \Factory \UserFactory ;
6
- use App \Tests \Browser \Authentication ;
7
6
use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
7
+ use Symfony \Component \BrowserKit \CookieJar ;
8
8
use Zenstruck \Browser \Test \HasBrowser ;
9
9
use Zenstruck \Foundry \Test \Factories ;
10
10
use Zenstruck \Foundry \Test \ResetDatabase ;
@@ -20,17 +20,17 @@ public function testCanLoginAndLogout(): void
20
20
UserFactory::
createOne ([
'email ' =>
'[email protected] ' ,
'password ' =>
'1234 ' ]);
21
21
22
22
$ this ->browser ()
23
- ->use (Authentication:: assertNotAuthenticated () )
23
+ ->assertNotAuthenticated ()
24
24
->visit ('/login ' )
25
25
->
fillField (
'Email ' ,
'[email protected] ' )
26
26
->fillField ('Password ' , '1234 ' )
27
27
->click ('Sign in ' )
28
28
->assertOn ('/ ' )
29
29
->assertSuccessful ()
30
- ->
use (Authentication:: assertAuthenticatedAs ( '[email protected] ' ) )
30
+ ->
assertAuthenticated ( '[email protected] ' )
31
31
->visit ('/logout ' )
32
32
->assertOn ('/ ' )
33
- ->use (Authentication:: assertNotAuthenticated () )
33
+ ->assertNotAuthenticated ()
34
34
;
35
35
}
36
36
@@ -39,13 +39,14 @@ public function testLoginWithTarget(): void
39
39
UserFactory::
createOne ([
'email ' =>
'[email protected] ' ,
'password ' =>
'1234 ' ]);
40
40
41
41
$ this ->browser ()
42
- ->use (Authentication:: assertNotAuthenticated () )
42
+ ->assertNotAuthenticated ()
43
43
->visit ('/login?target=/some/page ' )
44
44
->
fillField (
'Email ' ,
'[email protected] ' )
45
45
->fillField ('Password ' , '1234 ' )
46
46
->click ('Sign in ' )
47
47
->assertOn ('/some/page ' )
48
- ->
use (Authentication::
assertAuthenticatedAs (
'[email protected] ' ))
48
+ ->visit ('/ ' )
49
+ ->
assertAuthenticated (
'[email protected] ' )
49
50
;
50
51
}
51
52
@@ -62,7 +63,7 @@ public function testLoginWithInvalidPassword(): void
62
63
->assertSuccessful ()
63
64
->
assertFieldEquals (
'Email ' ,
'[email protected] ' )
64
65
->assertSee ('Invalid credentials. ' )
65
- ->use (Authentication:: assertNotAuthenticated () )
66
+ ->assertNotAuthenticated ()
66
67
;
67
68
}
68
69
@@ -77,7 +78,7 @@ public function testLoginWithInvalidEmail(): void
77
78
->assertSuccessful ()
78
79
->
assertFieldEquals (
'Email ' ,
'[email protected] ' )
79
80
->assertSee ('Invalid credentials. ' )
80
- ->use (Authentication:: assertNotAuthenticated () )
81
+ ->assertNotAuthenticated ()
81
82
;
82
83
}
83
84
@@ -86,12 +87,12 @@ public function testLoginWithInvalidCsrf(): void
86
87
UserFactory::
createOne ([
'email ' =>
'[email protected] ' ,
'password ' =>
'1234 ' ]);
87
88
88
89
$ this ->browser ()
89
- ->use (Authentication:: assertNotAuthenticated () )
90
+ ->assertNotAuthenticated ()
90
91
->
post (
'/login ' , [
'body ' => [
'email ' =>
'[email protected] ' ,
'password ' =>
'1234 ' ]])
91
92
->assertOn ('/login ' )
92
93
->assertSuccessful ()
93
94
->assertSee ('Invalid CSRF token. ' )
94
- ->use (Authentication:: assertNotAuthenticated () )
95
+ ->assertNotAuthenticated ()
95
96
;
96
97
}
97
98
@@ -106,9 +107,13 @@ public function testRememberMeEnabledByDefault(): void
106
107
->click ('Sign in ' )
107
108
->assertOn ('/ ' )
108
109
->assertSuccessful ()
109
- ->
use (Authentication::
assertAuthenticatedAs (
'[email protected] ' ))
110
- ->use (Authentication::expireSession ())
111
- ->
use (Authentication::
assertAuthenticatedAs (
'[email protected] ' ))
110
+ ->
assertAuthenticated (
'[email protected] ' )
111
+ ->use (function (CookieJar $ cookieJar ) {
112
+ $ cookieJar ->expire ('MOCKSESSID ' );
113
+ })
114
+ ->withProfiling ()
115
+ ->visit ('/ ' )
116
+ ->
assertAuthenticated (
'[email protected] ' )
112
117
;
113
118
}
114
119
@@ -124,9 +129,12 @@ public function testCanDisableRememberMe(): void
124
129
->click ('Sign in ' )
125
130
->assertOn ('/ ' )
126
131
->assertSuccessful ()
127
- ->
use (Authentication::
assertAuthenticatedAs (
'[email protected] ' ))
128
- ->use (Authentication::expireSession ())
129
- ->use (Authentication::assertNotAuthenticated ())
132
+ ->
assertAuthenticated (
'[email protected] ' )
133
+ ->use (function (CookieJar $ cookieJar ) {
134
+ $ cookieJar ->expire ('MOCKSESSID ' );
135
+ })
136
+ ->visit ('/ ' )
137
+ ->assertNotAuthenticated ()
130
138
;
131
139
}
132
140
@@ -140,10 +148,10 @@ public function testFullyAuthenticatedLoginRedirect(): void
140
148
->fillField ('Password ' , '1234 ' )
141
149
->click ('Sign in ' )
142
150
->assertOn ('/ ' )
143
- ->use (Authentication:: assertAuthenticated () )
151
+ ->assertAuthenticated ()
144
152
->visit ('/login ' )
145
153
->assertOn ('/ ' )
146
- ->use (Authentication:: assertAuthenticated () )
154
+ ->assertAuthenticated ()
147
155
;
148
156
}
149
157
@@ -157,10 +165,11 @@ public function testFullyAuthenticatedLoginTarget(): void
157
165
->fillField ('Password ' , '1234 ' )
158
166
->click ('Sign in ' )
159
167
->assertOn ('/ ' )
160
- ->use (Authentication:: assertAuthenticated () )
168
+ ->assertAuthenticated ()
161
169
->visit ('/login?target=/some/page ' )
162
170
->assertOn ('/some/page ' )
163
- ->use (Authentication::assertAuthenticated ())
171
+ ->visit ('/ ' )
172
+ ->assertAuthenticated ()
164
173
;
165
174
}
166
175
@@ -174,14 +183,16 @@ public function testCanFullyAuthenticateIfOnlyRemembered(): void
174
183
->fillField ('Password ' , '1234 ' )
175
184
->click ('Sign in ' )
176
185
->assertOn ('/ ' )
177
- ->
use (Authentication::
assertAuthenticatedAs (
'[email protected] ' ))
178
- ->use (Authentication::expireSession ())
186
+ ->
assertAuthenticated (
'[email protected] ' )
187
+ ->use (function (CookieJar $ cookieJar ) {
188
+ $ cookieJar ->expire ('MOCKSESSID ' );
189
+ })
179
190
->visit ('/login ' )
180
191
->assertOn ('/login ' )
181
192
->fillField ('Password ' , '1234 ' )
182
193
->click ('Sign in ' )
183
194
->assertOn ('/ ' )
184
- ->
use (Authentication:: assertAuthenticatedAs ( '[email protected] ' ) )
195
+ ->
assertAuthenticated ( '[email protected] ' )
185
196
;
186
197
}
187
198
@@ -196,14 +207,14 @@ public function testLegacyPasswordHashIsAutomaticallyMigratedOnLogin(): void
196
207
$ this ->assertSame (\PASSWORD_ARGON2ID , password_get_info ($ user ->getPassword ())['algo ' ]);
197
208
198
209
$ this ->browser ()
199
- ->use (Authentication:: assertNotAuthenticated () )
210
+ ->assertNotAuthenticated ()
200
211
->visit ('/login ' )
201
212
->
fillField (
'Email ' ,
'[email protected] ' )
202
213
->fillField ('Password ' , '1234 ' )
203
214
->click ('Sign in ' )
204
215
->assertOn ('/ ' )
205
216
->assertSuccessful ()
206
- ->
use (Authentication:: assertAuthenticatedAs ( '[email protected] ' ) )
217
+ ->
assertAuthenticated ( '[email protected] ' )
207
218
;
208
219
209
220
$ this ->assertSame (\PASSWORD_DEFAULT , password_get_info ($ user ->getPassword ())['algo ' ]);
0 commit comments