@@ -24,15 +24,9 @@ final class ConsoleCommandListenerTest extends TestCase
2424 */
2525 private $ hub ;
2626
27- /**
28- * @var ConsoleCommandListener
29- */
30- private $ listener ;
31-
3227 protected function setUp (): void
3328 {
3429 $ this ->hub = $ this ->createMock (HubInterface::class);
35- $ this ->listener = new ConsoleCommandListener ($ this ->hub );
3630 }
3731
3832 /**
@@ -43,12 +37,13 @@ protected function setUp(): void
4337 public function testHandleConsoleCommandEvent (ConsoleCommandEvent $ consoleEvent , array $ expectedTags ): void
4438 {
4539 $ scope = new Scope ();
40+ $ listener = new ConsoleCommandListener ($ this ->hub );
4641
4742 $ this ->hub ->expects ($ this ->once ())
4843 ->method ('pushScope ' )
4944 ->willReturn ($ scope );
5045
51- $ this -> listener ->handleConsoleCommandEvent ($ consoleEvent );
46+ $ listener ->handleConsoleCommandEvent ($ consoleEvent );
5247
5348 $ event = $ scope ->applyToEvent (Event::createEvent ());
5449
@@ -78,31 +73,46 @@ public function handleConsoleCommmandEventDataProvider(): \Generator
7873
7974 public function testHandleConsoleTerminateEvent (): void
8075 {
76+ $ listener = new ConsoleCommandListener ($ this ->hub );
77+
8178 $ this ->hub ->expects ($ this ->once ())
8279 ->method ('popScope ' );
8380
84- $ this -> listener ->handleConsoleTerminateEvent (new ConsoleTerminateEvent (new Command (), $ this ->createMock (InputInterface::class), $ this ->createMock (OutputInterface::class), 0 ));
81+ $ listener ->handleConsoleTerminateEvent (new ConsoleTerminateEvent (new Command (), $ this ->createMock (InputInterface::class), $ this ->createMock (OutputInterface::class), 0 ));
8582 }
8683
87- public function testHandleConsoleErrorEvent (): void
84+ /**
85+ * @dataProvider handleConsoleErrorEventDataProvider
86+ */
87+ public function testHandleConsoleErrorEvent (bool $ captureErrors ): void
8888 {
8989 $ scope = new Scope ();
9090 $ consoleEvent = new ConsoleErrorEvent ($ this ->createMock (InputInterface::class), $ this ->createMock (OutputInterface::class), new \Exception ());
91+ $ listener = new ConsoleCommandListener ($ this ->hub , $ captureErrors );
9192
9293 $ this ->hub ->expects ($ this ->once ())
9394 ->method ('configureScope ' )
9495 ->willReturnCallback (static function (callable $ callback ) use ($ scope ): void {
9596 $ callback ($ scope );
9697 });
9798
98- $ this ->hub ->expects ($ this ->once ())
99+ $ this ->hub ->expects ($ captureErrors ? $ this ->once () : $ this -> never ())
99100 ->method ('captureException ' )
100101 ->with ($ consoleEvent ->getError ());
101102
102- $ this -> listener ->handleConsoleErrorEvent ($ consoleEvent );
103+ $ listener ->handleConsoleErrorEvent ($ consoleEvent );
103104
104105 $ event = $ scope ->applyToEvent (Event::createEvent ());
105106
106107 $ this ->assertSame (['console.command.exit_code ' => '1 ' ], $ event ->getTags ());
107108 }
109+
110+ /**
111+ * @return \Generator<mixed>
112+ */
113+ public function handleConsoleErrorEventDataProvider (): \Generator
114+ {
115+ yield [true ];
116+ yield [false ];
117+ }
108118}
0 commit comments