@@ -131,26 +131,35 @@ private function getPhpProcess($fileName, ArrayObject $args)
131131 public function verify (Input $ input )
132132 {
133133 $ this ->eventDispatcher ->dispatch (new ExerciseRunnerEvent ('cli.verify.start ' , $ this ->exercise , $ input ));
134- //BC - getArgs only returned 1 set of args in v1 instead of multiple sets of args in v2
135- $ args = $ this ->exercise ->getArgs ();
136- if (isset ($ args [0 ]) && !is_array ($ args [0 ])) {
137- $ args = [$ args ];
138- } elseif (empty ($ args )) {
139- $ args = [[]];
140- }
141- //END BC
142134 $ result = new CliResult (
143135 array_map (
144136 function (array $ args ) use ($ input ) {
145137 return $ this ->doVerify ($ args , $ input );
146138 },
147- $ args
139+ $ this -> preserveOldArgFormat ( $ this -> exercise -> getArgs ())
148140 )
149141 );
150142 $ this ->eventDispatcher ->dispatch (new ExerciseRunnerEvent ('cli.verify.finish ' , $ this ->exercise , $ input ));
151143 return $ result ;
152144 }
153145
146+ /**
147+ * BC - getArgs only returned 1 set of args in v1 instead of multiple sets of args in v2
148+ *
149+ * @param array $args
150+ * @return array
151+ */
152+ private function preserveOldArgFormat (array $ args )
153+ {
154+ if (isset ($ args [0 ]) && !is_array ($ args [0 ])) {
155+ $ args = [$ args ];
156+ } elseif (empty ($ args )) {
157+ $ args = [[]];
158+ }
159+
160+ return $ args ;
161+ }
162+
154163 /**
155164 * @param array $args
156165 * @param Input $input
@@ -206,32 +215,42 @@ private function doVerify(array $args, Input $input)
206215 public function run (Input $ input , OutputInterface $ output )
207216 {
208217 $ this ->eventDispatcher ->dispatch (new ExerciseRunnerEvent ('cli.run.start ' , $ this ->exercise , $ input ));
209- /** @var CliExecuteEvent $event */
210- $ event = $ this ->eventDispatcher ->dispatch (
211- new CliExecuteEvent ('cli.run.student-execute.pre ' , new ArrayObject ($ this ->exercise ->getArgs ()))
212- );
218+ $ success = true ;
219+ foreach ($ this ->preserveOldArgFormat ($ this ->exercise ->getArgs ()) as $ i => $ args ) {
220+ /** @var CliExecuteEvent $event */
221+ $ event = $ this ->eventDispatcher ->dispatch (
222+ new CliExecuteEvent ('cli.run.student-execute.pre ' , new ArrayObject ($ args ))
223+ );
213224
214- $ args = $ event ->getArgs ();
225+ $ args = $ event ->getArgs ();
215226
216- if (count ($ args )) {
217- $ glue = max (array_map ('strlen ' , $ args ->getArrayCopy ())) > 30 ? "\n" : ', ' ;
227+ if (count ($ args )) {
228+ $ glue = max (array_map ('strlen ' , $ args ->getArrayCopy ())) > 30 ? "\n" : ', ' ;
218229
219- $ output ->writeTitle ('Arguments ' );
220- $ output ->write (implode ($ glue , $ args ->getArrayCopy ()));
230+ $ output ->writeTitle ('Arguments ' );
231+ $ output ->write (implode ($ glue , $ args ->getArrayCopy ()));
232+ $ output ->emptyLine ();
233+ }
234+
235+ $ output ->writeTitle ("Output " );
236+ $ process = $ this ->getPhpProcess ($ input ->getArgument ('program ' ), $ args );
237+ $ process ->start ();
238+ $ this ->eventDispatcher ->dispatch (
239+ new CliExecuteEvent ('cli.run.student.executing ' , $ args , ['output ' => $ output ])
240+ );
241+ $ process ->wait (function ($ outputType , $ outputBuffer ) use ($ output ) {
242+ $ output ->write ($ outputBuffer );
243+ });
221244 $ output ->emptyLine ();
222- }
223245
224- $ output ->writeTitle ("Output " );
225- $ process = $ this ->getPhpProcess ($ input ->getArgument ('program ' ), $ args );
226- $ process ->start ();
227- $ this ->eventDispatcher ->dispatch (
228- new CliExecuteEvent ('cli.run.student.executing ' , $ args , ['output ' => $ output ])
229- );
230- $ process ->wait (function ($ outputType , $ outputBuffer ) use ($ output ) {
231- $ output ->writeLine ($ outputBuffer );
232- });
246+ if (!$ process ->isSuccessful ()) {
247+ $ success = false ;
248+ }
249+
250+ $ output ->lineBreak ();
251+ }
233252
234253 $ this ->eventDispatcher ->dispatch (new ExerciseRunnerEvent ('cli.run.finish ' , $ this ->exercise , $ input ));
235- return $ process -> isSuccessful () ;
254+ return $ success ;
236255 }
237256}
0 commit comments