4
4
5
5
use PHPUnit \Framework \TestCase ;
6
6
use Prophecy \Argument ;
7
+ use Sentry \ClientInterface ;
8
+ use Sentry \Options ;
7
9
use Sentry \SentryBundle \EventListener \RequestListener ;
8
10
use Sentry \State \Hub ;
9
11
use Sentry \State \HubInterface ;
@@ -21,13 +23,24 @@ class RequestListenerTest extends TestCase
21
23
{
22
24
private $ currentScope ;
23
25
private $ currentHub ;
26
+ private $ options ;
24
27
25
28
protected function setUp ()
26
29
{
27
30
parent ::setUp ();
28
31
29
32
$ this ->currentScope = $ scope = new Scope ();
30
33
$ this ->currentHub = $ this ->prophesize (HubInterface::class);
34
+
35
+ $ client = $ this ->prophesize (ClientInterface::class);
36
+ $ this ->options = new Options ();
37
+
38
+ $ this ->currentHub ->getClient ()
39
+ ->willReturn ($ client ->reveal ());
40
+ $ client ->getOptions ()
41
+ ->willReturn ($ this ->options );
42
+ $ this ->options ->setSendDefaultPii (true );
43
+
31
44
$ this ->currentHub ->configureScope (Argument::type ('callable ' ))
32
45
->shouldBeCalled ()
33
46
->will (function ($ arguments ) use ($ scope ): void {
@@ -96,6 +109,56 @@ public function userDataProvider(): \Generator
96
109
yield [new ToStringUser ('john-doe ' )];
97
110
}
98
111
112
+ public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled (): void
113
+ {
114
+ $ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
115
+ $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
116
+ $ event = $ this ->prophesize (GetResponseEvent::class);
117
+
118
+ $ event ->isMasterRequest ()
119
+ ->willReturn (true );
120
+
121
+ $ this ->options ->setSendDefaultPii (false );
122
+
123
+ $ this ->currentHub ->configureScope (Argument::type ('callable ' ))
124
+ ->shouldNotBeCalled ();
125
+
126
+ $ listener = new RequestListener (
127
+ $ this ->currentHub ->reveal (),
128
+ $ tokenStorage ->reveal (),
129
+ $ authorizationChecker ->reveal ()
130
+ );
131
+
132
+ $ listener ->onKernelRequest ($ event ->reveal ());
133
+
134
+ $ this ->assertEquals ([], $ this ->currentScope ->getUser ());
135
+ }
136
+
137
+ public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent (): void
138
+ {
139
+ $ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
140
+ $ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
141
+ $ event = $ this ->prophesize (GetResponseEvent::class);
142
+
143
+ $ event ->isMasterRequest ()
144
+ ->willReturn (true );
145
+
146
+ $ this ->currentHub ->getClient ()
147
+ ->willReturn (null );
148
+ $ this ->currentHub ->configureScope (Argument::type ('callable ' ))
149
+ ->shouldNotBeCalled ();
150
+
151
+ $ listener = new RequestListener (
152
+ $ this ->currentHub ->reveal (),
153
+ $ tokenStorage ->reveal (),
154
+ $ authorizationChecker ->reveal ()
155
+ );
156
+
157
+ $ listener ->onKernelRequest ($ event ->reveal ());
158
+
159
+ $ this ->assertEquals ([], $ this ->currentScope ->getUser ());
160
+ }
161
+
99
162
public function testOnKernelRequestUsernameIsNotSetIfTokenStorageIsAbsent (): void
100
163
{
101
164
$ authorizationChecker = $ this ->prophesize (AuthorizationCheckerInterface::class);
0 commit comments