File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
and this project adheres to [ Semantic Versioning] ( http://semver.org/spec/v2.0.0.html ) .
6
6
7
7
## Unreleased
8
+ - Fix handling of command with no name on ` ConsoleListener ` (#261 )
8
9
9
10
## 3.2.0 (2019-10-04)
10
11
Original file line number Diff line number Diff line change @@ -33,9 +33,14 @@ public function onConsoleCommand(ConsoleCommandEvent $event): void
33
33
{
34
34
$ command = $ event ->getCommand ();
35
35
36
+ $ commandName = null ;
37
+ if ($ command ) {
38
+ $ commandName = $ command ->getName ();
39
+ }
40
+
36
41
SentryBundle::getCurrentHub ()
37
- ->configureScope (function (Scope $ scope ) use ($ command ): void {
38
- $ scope ->setTag ('command ' , $ command ? $ command -> getName () : 'N/A ' );
42
+ ->configureScope (static function (Scope $ scope ) use ($ commandName ): void {
43
+ $ scope ->setTag ('command ' , $ commandName ?? 'N/A ' );
39
44
});
40
45
}
41
46
}
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ public function testOnConsoleCommandAddsCommandName(): void
51
51
$ this ->assertSame (['command ' => 'sf:command:name ' ], $ this ->getTagsContext ($ this ->currentScope ));
52
52
}
53
53
54
- public function testOnConsoleCommandAddsPlaceholderCommandName (): void
54
+ public function testOnConsoleCommandWithNoCommandAddsPlaceholder (): void
55
55
{
56
56
$ event = $ this ->prophesize (ConsoleCommandEvent::class);
57
57
$ event ->getCommand ()
@@ -64,6 +64,23 @@ public function testOnConsoleCommandAddsPlaceholderCommandName(): void
64
64
$ this ->assertSame (['command ' => 'N/A ' ], $ this ->getTagsContext ($ this ->currentScope ));
65
65
}
66
66
67
+ public function testOnConsoleCommandWithNoCommandNameAddsPlaceholder (): void
68
+ {
69
+ $ command = $ this ->prophesize (Command::class);
70
+ $ command ->getName ()
71
+ ->willReturn (null );
72
+
73
+ $ event = $ this ->prophesize (ConsoleCommandEvent::class);
74
+ $ event ->getCommand ()
75
+ ->willReturn ($ command ->reveal ());
76
+
77
+ $ listener = new ConsoleListener ($ this ->currentHub ->reveal ());
78
+
79
+ $ listener ->onConsoleCommand ($ event ->reveal ());
80
+
81
+ $ this ->assertSame (['command ' => 'N/A ' ], $ this ->getTagsContext ($ this ->currentScope ));
82
+ }
83
+
67
84
private function getTagsContext (Scope $ scope ): array
68
85
{
69
86
$ event = new Event ();
You can’t perform that action at this time.
0 commit comments