@@ -24,15 +24,9 @@ final class ConsoleCommandListenerTest extends TestCase
24
24
*/
25
25
private $ hub ;
26
26
27
- /**
28
- * @var ConsoleCommandListener
29
- */
30
- private $ listener ;
31
-
32
27
protected function setUp (): void
33
28
{
34
29
$ this ->hub = $ this ->createMock (HubInterface::class);
35
- $ this ->listener = new ConsoleCommandListener ($ this ->hub );
36
30
}
37
31
38
32
/**
@@ -43,12 +37,13 @@ protected function setUp(): void
43
37
public function testHandleConsoleCommandEvent (ConsoleCommandEvent $ consoleEvent , array $ expectedTags ): void
44
38
{
45
39
$ scope = new Scope ();
40
+ $ listener = new ConsoleCommandListener ($ this ->hub );
46
41
47
42
$ this ->hub ->expects ($ this ->once ())
48
43
->method ('pushScope ' )
49
44
->willReturn ($ scope );
50
45
51
- $ this -> listener ->handleConsoleCommandEvent ($ consoleEvent );
46
+ $ listener ->handleConsoleCommandEvent ($ consoleEvent );
52
47
53
48
$ event = $ scope ->applyToEvent (Event::createEvent ());
54
49
@@ -78,31 +73,46 @@ public function handleConsoleCommmandEventDataProvider(): \Generator
78
73
79
74
public function testHandleConsoleTerminateEvent (): void
80
75
{
76
+ $ listener = new ConsoleCommandListener ($ this ->hub );
77
+
81
78
$ this ->hub ->expects ($ this ->once ())
82
79
->method ('popScope ' );
83
80
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 ));
85
82
}
86
83
87
- public function testHandleConsoleErrorEvent (): void
84
+ /**
85
+ * @dataProvider handleConsoleErrorEventDataProvider
86
+ */
87
+ public function testHandleConsoleErrorEvent (bool $ captureErrors ): void
88
88
{
89
89
$ scope = new Scope ();
90
90
$ consoleEvent = new ConsoleErrorEvent ($ this ->createMock (InputInterface::class), $ this ->createMock (OutputInterface::class), new \Exception ());
91
+ $ listener = new ConsoleCommandListener ($ this ->hub , $ captureErrors );
91
92
92
93
$ this ->hub ->expects ($ this ->once ())
93
94
->method ('configureScope ' )
94
95
->willReturnCallback (static function (callable $ callback ) use ($ scope ): void {
95
96
$ callback ($ scope );
96
97
});
97
98
98
- $ this ->hub ->expects ($ this ->once ())
99
+ $ this ->hub ->expects ($ captureErrors ? $ this ->once () : $ this -> never ())
99
100
->method ('captureException ' )
100
101
->with ($ consoleEvent ->getError ());
101
102
102
- $ this -> listener ->handleConsoleErrorEvent ($ consoleEvent );
103
+ $ listener ->handleConsoleErrorEvent ($ consoleEvent );
103
104
104
105
$ event = $ scope ->applyToEvent (Event::createEvent ());
105
106
106
107
$ this ->assertSame (['console.command.exit_code ' => '1 ' ], $ event ->getTags ());
107
108
}
109
+
110
+ /**
111
+ * @return \Generator<mixed>
112
+ */
113
+ public function handleConsoleErrorEventDataProvider (): \Generator
114
+ {
115
+ yield [true ];
116
+ yield [false ];
117
+ }
108
118
}
0 commit comments