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/)
55and this project adheres to [ Semantic Versioning] ( http://semver.org/spec/v2.0.0.html ) .
66
77## Unreleased
8+ - Fix handling of command with no name on ` ConsoleListener ` (#261 )
89
910## 3.2.0 (2019-10-04)
1011
Original file line number Diff line number Diff line change @@ -33,9 +33,14 @@ public function onConsoleCommand(ConsoleCommandEvent $event): void
3333 {
3434 $ command = $ event ->getCommand ();
3535
36+ $ commandName = null ;
37+ if ($ command ) {
38+ $ commandName = $ command ->getName ();
39+ }
40+
3641 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 ' );
3944 });
4045 }
4146}
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ public function testOnConsoleCommandAddsCommandName(): void
5151 $ this ->assertSame (['command ' => 'sf:command:name ' ], $ this ->getTagsContext ($ this ->currentScope ));
5252 }
5353
54- public function testOnConsoleCommandAddsPlaceholderCommandName (): void
54+ public function testOnConsoleCommandWithNoCommandAddsPlaceholder (): void
5555 {
5656 $ event = $ this ->prophesize (ConsoleCommandEvent::class);
5757 $ event ->getCommand ()
@@ -64,6 +64,23 @@ public function testOnConsoleCommandAddsPlaceholderCommandName(): void
6464 $ this ->assertSame (['command ' => 'N/A ' ], $ this ->getTagsContext ($ this ->currentScope ));
6565 }
6666
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+
6784 private function getTagsContext (Scope $ scope ): array
6885 {
6986 $ event = new Event ();
You can’t perform that action at this time.
0 commit comments