File tree Expand file tree Collapse file tree 4 files changed +32
-13
lines changed Expand file tree Collapse file tree 4 files changed +32
-13
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use Sentry \State \Hub ;
6
6
use Sentry \State \HubInterface ;
7
+ use Sentry \State \Scope ;
7
8
use Symfony \Component \Console \Event \ConsoleCommandEvent ;
8
9
9
10
final class ConsoleListener
@@ -33,7 +34,8 @@ public function onConsoleCommand(ConsoleCommandEvent $event): void
33
34
$ command = $ event ->getCommand ();
34
35
35
36
Hub::getCurrent ()
36
- ->getScope ()
37
- ->setTag ('command ' , $ command ? $ command ->getName () : 'N/A ' );
37
+ ->configureScope (function (Scope $ scope ) use ($ command ): void {
38
+ $ scope ->setTag ('command ' , $ command ? $ command ->getName () : 'N/A ' );
39
+ });
38
40
}
39
41
}
Original file line number Diff line number Diff line change 4
4
5
5
use Sentry \State \Hub ;
6
6
use Sentry \State \HubInterface ;
7
+ use Sentry \State \Scope ;
7
8
use Symfony \Component \HttpKernel \Event \FilterControllerEvent ;
8
9
use Symfony \Component \HttpKernel \Event \GetResponseEvent ;
9
10
use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
@@ -71,8 +72,9 @@ public function onKernelRequest(GetResponseEvent $event): void
71
72
$ userData ['ip_address ' ] = $ event ->getRequest ()->getClientIp ();
72
73
73
74
Hub::getCurrent ()
74
- ->getScope ()
75
- ->setUser ($ userData );
75
+ ->configureScope (function (Scope $ scope ) use ($ userData ): void {
76
+ $ scope ->setUser ($ userData );
77
+ });
76
78
}
77
79
78
80
public function onKernelController (FilterControllerEvent $ event ): void
@@ -84,8 +86,9 @@ public function onKernelController(FilterControllerEvent $event): void
84
86
$ matchedRoute = $ event ->getRequest ()->attributes ->get ('_route ' );
85
87
86
88
Hub::getCurrent ()
87
- ->getScope ()
88
- ->setTag ('route ' , $ matchedRoute );
89
+ ->configureScope (function (Scope $ scope ) use ($ matchedRoute ): void {
90
+ $ scope ->setTag ('route ' , $ matchedRoute );
91
+ });
89
92
}
90
93
91
94
/**
Original file line number Diff line number Diff line change 2
2
3
3
namespace Sentry \SentryBundle \Test \EventListener ;
4
4
5
+ use PHPUnit \Framework \Assert ;
6
+ use Prophecy \Argument ;
5
7
use Sentry \SentryBundle \EventListener \ConsoleListener ;
6
8
use Sentry \State \Hub ;
7
9
use Sentry \State \HubInterface ;
@@ -18,11 +20,16 @@ protected function setUp()
18
20
{
19
21
parent ::setUp ();
20
22
21
- $ this ->currentScope = new Scope ();
23
+ $ this ->currentScope = $ scope = new Scope ();
22
24
$ this ->currentHub = $ this ->prophesize (HubInterface::class);
23
- $ this ->currentHub ->getScope ( )
25
+ $ this ->currentHub ->configureScope (Argument:: type ( ' callable ' ) )
24
26
->shouldBeCalled ()
25
- ->willReturn ($ this ->currentScope );
27
+ ->will (function ($ arguments ) use ($ scope ): void {
28
+ $ callable = $ arguments [0 ];
29
+ Assert::assertIsCallable ($ callable );
30
+
31
+ $ callable ($ scope );
32
+ });
26
33
27
34
Hub::setCurrent ($ this ->currentHub ->reveal ());
28
35
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace Sentry \SentryBundle \Test \EventListener ;
4
4
5
+ use PHPUnit \Framework \Assert ;
5
6
use PHPUnit \Framework \TestCase ;
7
+ use Prophecy \Argument ;
6
8
use Sentry \SentryBundle \EventListener \RequestListener ;
7
9
use Sentry \State \Hub ;
8
10
use Sentry \State \HubInterface ;
@@ -25,11 +27,16 @@ protected function setUp()
25
27
{
26
28
parent ::setUp ();
27
29
28
- $ this ->currentScope = new Scope ();
30
+ $ this ->currentScope = $ scope = new Scope ();
29
31
$ this ->currentHub = $ this ->prophesize (HubInterface::class);
30
- $ this ->currentHub ->getScope ( )
32
+ $ this ->currentHub ->configureScope (Argument:: type ( ' callable ' ) )
31
33
->shouldBeCalled ()
32
- ->willReturn ($ this ->currentScope );
34
+ ->will (function ($ arguments ) use ($ scope ): void {
35
+ $ callable = $ arguments [0 ];
36
+ Assert::assertIsCallable ($ callable );
37
+
38
+ $ callable ($ scope );
39
+ });
33
40
34
41
Hub::setCurrent ($ this ->currentHub ->reveal ());
35
42
}
@@ -289,7 +296,7 @@ public function testOnKernelControllerAddsRouteTag(): void
289
296
290
297
public function testOnKernelRequestUserDataAndTagsAreNotSetInSubRequest (): void
291
298
{
292
- $ this ->currentHub ->getScope ( )
299
+ $ this ->currentHub ->configureScope (Argument:: type ( ' callable ' ) )
293
300
->shouldNotBeCalled ();
294
301
295
302
$ tokenStorage = $ this ->prophesize (TokenStorageInterface::class);
You can’t perform that action at this time.
0 commit comments