5
5
use PHPUnit \Framework \TestCase ;
6
6
use Prophecy \Argument ;
7
7
use Sentry \ClientInterface ;
8
+ use Sentry \Event ;
8
9
use Sentry \Options ;
9
10
use Sentry \SentryBundle \EventListener \RequestListener ;
10
11
use Sentry \State \Hub ;
@@ -94,7 +95,7 @@ public function testOnKernelRequestUserDataIsSetToScope($user): void
94
95
'ip_address ' => '1.2.3.4 ' ,
95
96
'username ' => 'john-doe ' ,
96
97
];
97
- $ this ->assertEquals ($ expectedUserData , $ this ->currentScope -> getUser ( ));
98
+ $ this ->assertEquals ($ expectedUserData , $ this ->getUserContext ( $ this -> currentScope ));
98
99
}
99
100
100
101
public function userDataProvider (): \Generator
@@ -131,7 +132,7 @@ public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled(): void
131
132
132
133
$ listener ->onKernelRequest ($ event ->reveal ());
133
134
134
- $ this ->assertEquals ([], $ this ->currentScope -> getUser ( ));
135
+ $ this ->assertEquals ([], $ this ->getUserContext ( $ this -> currentScope ));
135
136
}
136
137
137
138
public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent (): void
@@ -156,7 +157,7 @@ public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void
156
157
157
158
$ listener ->onKernelRequest ($ event ->reveal ());
158
159
159
- $ this ->assertEquals ([], $ this ->currentScope -> getUser ( ));
160
+ $ this ->assertEquals ([], $ this ->getUserContext ( $ this -> currentScope ));
160
161
}
161
162
162
163
public function testOnKernelRequestUsernameIsNotSetIfTokenStorageIsAbsent (): void
@@ -187,7 +188,7 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenStorageIsAbsent(): voi
187
188
$ expectedUserData = [
188
189
'ip_address ' => '1.2.3.4 ' ,
189
190
];
190
- $ this ->assertEquals ($ expectedUserData , $ this ->currentScope -> getUser ( ));
191
+ $ this ->assertEquals ($ expectedUserData , $ this ->getUserContext ( $ this -> currentScope ));
191
192
}
192
193
193
194
public function testOnKernelRequestUsernameIsNotSetIfAuthorizationCheckerIsAbsent (): void
@@ -218,7 +219,7 @@ public function testOnKernelRequestUsernameIsNotSetIfAuthorizationCheckerIsAbsen
218
219
$ expectedUserData = [
219
220
'ip_address ' => '1.2.3.4 ' ,
220
221
];
221
- $ this ->assertEquals ($ expectedUserData , $ this ->currentScope -> getUser ( ));
222
+ $ this ->assertEquals ($ expectedUserData , $ this ->getUserContext ( $ this -> currentScope ));
222
223
}
223
224
224
225
public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent (): void
@@ -253,7 +254,7 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
253
254
$ expectedUserData = [
254
255
'ip_address ' => '1.2.3.4 ' ,
255
256
];
256
- $ this ->assertEquals ($ expectedUserData , $ this ->currentScope -> getUser ( ));
257
+ $ this ->assertEquals ($ expectedUserData , $ this ->getUserContext ( $ this -> currentScope ));
257
258
}
258
259
259
260
/**
@@ -295,7 +296,7 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated():
295
296
$ expectedUserData = [
296
297
'ip_address ' => '1.2.3.4 ' ,
297
298
];
298
- $ this ->assertEquals ($ expectedUserData , $ this ->currentScope -> getUser ( ));
299
+ $ this ->assertEquals ($ expectedUserData , $ this ->getUserContext ( $ this -> currentScope ));
299
300
}
300
301
301
302
public function testOnKernelRequestUsernameIsNotSetIfUserIsNotRemembered (): void
@@ -330,7 +331,7 @@ public function testOnKernelRequestUsernameIsNotSetIfUserIsNotRemembered(): void
330
331
$ expectedUserData = [
331
332
'ip_address ' => '1.2.3.4 ' ,
332
333
];
333
- $ this ->assertEquals ($ expectedUserData , $ this ->currentScope -> getUser ( ));
334
+ $ this ->assertEquals ($ expectedUserData , $ this ->getUserContext ( $ this -> currentScope ));
334
335
}
335
336
336
337
public function testOnKernelControllerAddsRouteTag (): void
@@ -403,9 +404,17 @@ public function testOnKernelRequestUserDataAndTagsAreNotSetInSubRequest(): void
403
404
404
405
$ listener ->onKernelRequest ($ event ->reveal ());
405
406
406
- $ this ->assertEmpty ($ this ->currentScope -> getUser ( ));
407
+ $ this ->assertEmpty ($ this ->getUserContext ( $ this -> currentScope ));
407
408
$ this ->assertEmpty ($ this ->currentScope ->getTags ());
408
409
}
410
+
411
+ private function getUserContext (Scope $ scope ): array
412
+ {
413
+ $ event = new Event ();
414
+ $ scope ->applyToEvent ($ event , []);
415
+
416
+ return $ event ->getUserContext ()->toArray ();
417
+ }
409
418
}
410
419
411
420
class ToStringUser
0 commit comments