19
19
use Symfony \Component \Console \EventListener \ExceptionListener ;
20
20
use Symfony \Component \Console \Input \ArgvInput ;
21
21
use Symfony \Component \Console \Input \ArrayInput ;
22
+ use Symfony \Component \Console \Input \Input ;
22
23
use Symfony \Component \Console \Input \StringInput ;
23
24
use Symfony \Component \Console \Input \InputInterface ;
24
25
use Symfony \Component \Console \Output \OutputInterface ;
@@ -37,7 +38,22 @@ public function testOnConsoleError()
37
38
;
38
39
39
40
$ listener = new ExceptionListener ($ logger );
40
- $ listener ->onConsoleError ($ this ->getConsoleErrorEvent ($ exception , new ArgvInput (array ('console.php ' , 'test:run ' , '--foo=baz ' , 'buzz ' )), 1 ));
41
+ $ listener ->onConsoleError ($ this ->getConsoleErrorEvent ($ exception , new ArgvInput (array ('console.php ' , 'test:run ' , '--foo=baz ' , 'buzz ' )), 1 , new Command ('test:run ' )));
42
+ }
43
+
44
+ public function testOnConsoleErrorWithNoCommandAndNoInputString ()
45
+ {
46
+ $ exception = new \RuntimeException ('An error occurred ' );
47
+
48
+ $ logger = $ this ->getLogger ();
49
+ $ logger
50
+ ->expects ($ this ->once ())
51
+ ->method ('error ' )
52
+ ->with ('An error occurred while using the console. Message: "{message}" ' , array ('error ' => $ exception , 'message ' => 'An error occurred ' ))
53
+ ;
54
+
55
+ $ listener = new ExceptionListener ($ logger );
56
+ $ listener ->onConsoleError ($ this ->getConsoleErrorEvent ($ exception , new NonStringInput (), 1 ));
41
57
}
42
58
43
59
public function testOnConsoleTerminateForNonZeroExitCodeWritesToLog ()
@@ -109,9 +125,9 @@ private function getLogger()
109
125
return $ this ->getMockForAbstractClass (LoggerInterface::class);
110
126
}
111
127
112
- private function getConsoleErrorEvent (\Exception $ exception , InputInterface $ input , $ exitCode )
128
+ private function getConsoleErrorEvent (\Exception $ exception , InputInterface $ input , $ exitCode, Command $ command = null )
113
129
{
114
- return new ConsoleErrorEvent ($ input , $ this ->getOutput (), $ exception , $ exitCode , new Command ( ' test:run ' ) );
130
+ return new ConsoleErrorEvent ($ input , $ this ->getOutput (), $ exception , $ exitCode , $ command );
115
131
}
116
132
117
133
private function getConsoleTerminateEvent (InputInterface $ input , $ exitCode )
@@ -124,3 +140,22 @@ private function getOutput()
124
140
return $ this ->getMockBuilder (OutputInterface::class)->getMock ();
125
141
}
126
142
}
143
+
144
+ class NonStringInput extends Input
145
+ {
146
+ public function getFirstArgument ()
147
+ {
148
+ }
149
+
150
+ public function hasParameterOption ($ values , $ onlyParams = false )
151
+ {
152
+ }
153
+
154
+ public function getParameterOption ($ values , $ default = false , $ onlyParams = false )
155
+ {
156
+ }
157
+
158
+ public function parse ()
159
+ {
160
+ }
161
+ }
0 commit comments