6
6
7
7
use PHPUnit \Framework \MockObject \MockObject ;
8
8
use PHPUnit \Framework \TestCase ;
9
+ use Sentry \ClientInterface ;
9
10
use Sentry \Event ;
11
+ use Sentry \Options ;
10
12
use Sentry \SentryBundle \EventListener \RequestListener ;
11
13
use Sentry \State \HubInterface ;
12
14
use Sentry \State \Scope ;
@@ -53,15 +55,19 @@ protected function setUp(): void
53
55
*
54
56
* @param GetResponseEvent|RequestEvent $requestEvent
55
57
*/
56
- public function testHandleKernelRequestEvent ($ requestEvent , ?TokenInterface $ token , UserDataBag $ expectedUser ): void
58
+ public function testHandleKernelRequestEvent ($ requestEvent , ?ClientInterface $ client , ? TokenInterface $ token , ? UserDataBag $ expectedUser ): void
57
59
{
58
60
$ scope = new Scope ();
59
61
60
- $ this ->tokenStorage ->expects ($ this ->once ())
62
+ $ this ->hub ->expects ($ this ->any ())
63
+ ->method ('getClient ' )
64
+ ->willReturn ($ client );
65
+
66
+ $ this ->tokenStorage ->expects ($ this ->any ())
61
67
->method ('getToken ' )
62
68
->willReturn ($ token );
63
69
64
- $ this ->hub ->expects ($ this ->once ())
70
+ $ this ->hub ->expects ($ this ->any ())
65
71
->method ('configureScope ' )
66
72
->willReturnCallback (static function (callable $ callback ) use ($ scope ): void {
67
73
$ callback ($ scope );
@@ -83,12 +89,35 @@ public function handleKernelRequestEventForSymfonyVersionLowerThan43DataProvider
83
89
return ;
84
90
}
85
91
92
+ yield 'event.requestType != MASTER_REQUEST ' => [
93
+ new GetResponseEvent (
94
+ $ this ->createMock (HttpKernelInterface::class),
95
+ new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
96
+ HttpKernelInterface::SUB_REQUEST
97
+ ),
98
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
99
+ null ,
100
+ null ,
101
+ ];
102
+
103
+ yield 'options.send_default_pii = FALSE ' => [
104
+ new GetResponseEvent (
105
+ $ this ->createMock (HttpKernelInterface::class),
106
+ new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
107
+ HttpKernelInterface::MASTER_REQUEST
108
+ ),
109
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => false ])),
110
+ null ,
111
+ null ,
112
+ ];
113
+
86
114
yield 'token IS NULL ' => [
87
115
new GetResponseEvent (
88
116
$ this ->createMock (HttpKernelInterface::class),
89
117
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
90
118
HttpKernelInterface::MASTER_REQUEST
91
119
),
120
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
92
121
null ,
93
122
UserDataBag::createFromUserIpAddress ('127.0.0.1 ' ),
94
123
];
@@ -99,6 +128,7 @@ public function handleKernelRequestEventForSymfonyVersionLowerThan43DataProvider
99
128
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
100
129
HttpKernelInterface::MASTER_REQUEST
101
130
),
131
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
102
132
new class () extends AbstractToken {
103
133
public function __construct ()
104
134
{
@@ -121,6 +151,7 @@ public function getCredentials()
121
151
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
122
152
HttpKernelInterface::MASTER_REQUEST
123
153
),
154
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
124
155
new class () extends AbstractToken {
125
156
public function __construct ()
126
157
{
@@ -143,6 +174,7 @@ public function getCredentials()
143
174
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
144
175
HttpKernelInterface::MASTER_REQUEST
145
176
),
177
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
146
178
new class () extends AbstractToken {
147
179
public function __construct ()
148
180
{
@@ -166,6 +198,7 @@ public function getCredentials()
166
198
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
167
199
HttpKernelInterface::MASTER_REQUEST
168
200
),
201
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
169
202
new class () extends AbstractToken {
170
203
public function __construct ()
171
204
{
@@ -213,6 +246,7 @@ public function getCredentials()
213
246
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
214
247
HttpKernelInterface::MASTER_REQUEST
215
248
),
249
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
216
250
new class () extends AbstractToken {
217
251
public function __construct ()
218
252
{
@@ -245,12 +279,35 @@ public function handleKernelRequestEventForSymfonyVersionAtLeast43DataProvider()
245
279
return ;
246
280
}
247
281
282
+ yield 'event.requestType != MASTER_REQUEST ' => [
283
+ new RequestEvent (
284
+ $ this ->createMock (HttpKernelInterface::class),
285
+ new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
286
+ HttpKernelInterface::SUB_REQUEST
287
+ ),
288
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
289
+ null ,
290
+ null ,
291
+ ];
292
+
293
+ yield 'options.send_default_pii = FALSE ' => [
294
+ new RequestEvent (
295
+ $ this ->createMock (HttpKernelInterface::class),
296
+ new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
297
+ HttpKernelInterface::MASTER_REQUEST
298
+ ),
299
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => false ])),
300
+ null ,
301
+ null ,
302
+ ];
303
+
248
304
yield 'token IS NULL ' => [
249
305
new RequestEvent (
250
306
$ this ->createMock (HttpKernelInterface::class),
251
307
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
252
308
HttpKernelInterface::MASTER_REQUEST
253
309
),
310
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
254
311
null ,
255
312
UserDataBag::createFromUserIpAddress ('127.0.0.1 ' ),
256
313
];
@@ -261,6 +318,7 @@ public function handleKernelRequestEventForSymfonyVersionAtLeast43DataProvider()
261
318
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
262
319
HttpKernelInterface::MASTER_REQUEST
263
320
),
321
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
264
322
new class () extends AbstractToken {
265
323
public function __construct ()
266
324
{
@@ -283,6 +341,7 @@ public function getCredentials()
283
341
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
284
342
HttpKernelInterface::MASTER_REQUEST
285
343
),
344
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
286
345
new class () extends AbstractToken {
287
346
public function __construct ()
288
347
{
@@ -305,6 +364,7 @@ public function getCredentials()
305
364
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
306
365
HttpKernelInterface::MASTER_REQUEST
307
366
),
367
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
308
368
new class () extends AbstractToken {
309
369
public function __construct ()
310
370
{
@@ -328,6 +388,7 @@ public function getCredentials()
328
388
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
329
389
HttpKernelInterface::MASTER_REQUEST
330
390
),
391
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
331
392
new class () extends AbstractToken {
332
393
public function __construct ()
333
394
{
@@ -375,6 +436,7 @@ public function getCredentials()
375
436
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
376
437
HttpKernelInterface::MASTER_REQUEST
377
438
),
439
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
378
440
new class () extends AbstractToken {
379
441
public function __construct ()
380
442
{
@@ -511,4 +573,14 @@ static function () {
511
573
],
512
574
];
513
575
}
576
+
577
+ private function getMockedClientWithOptions (Options $ options ): ClientInterface
578
+ {
579
+ $ client = $ this ->createMock (ClientInterface::class);
580
+ $ client ->expects ($ this ->any ())
581
+ ->method ('getOptions ' )
582
+ ->willReturn ($ options );
583
+
584
+ return $ client ;
585
+ }
514
586
}
0 commit comments