File tree 4 files changed +61
-0
lines changed
src/Symfony/Component/Process 4 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ CHANGELOG
6
6
7
7
* added the ability to define an idle timeout
8
8
* added support for PTY mode
9
+ * added the convenience method "mustRun"
9
10
10
11
2.3.0
11
12
-----
Original file line number Diff line number Diff line change 13
13
14
14
use Symfony \Component \Process \Exception \InvalidArgumentException ;
15
15
use Symfony \Component \Process \Exception \LogicException ;
16
+ use Symfony \Component \Process \Exception \ProcessFailedException ;
16
17
use Symfony \Component \Process \Exception \ProcessTimedOutException ;
17
18
use Symfony \Component \Process \Exception \RuntimeException ;
18
19
@@ -209,6 +210,25 @@ public function run($callback = null)
209
210
return $ this ->wait ($ callback );
210
211
}
211
212
213
+ /**
214
+ * Runs the process.
215
+ *
216
+ * This is identical to run() except that an exception is thrown if the process
217
+ * exits with a non-zero exit code.
218
+ *
219
+ * @param callable|null $callback
220
+ *
221
+ * @return self
222
+ */
223
+ public function mustRun ($ callback = null )
224
+ {
225
+ if (0 !== $ this ->run ($ callback )) {
226
+ throw new ProcessFailedException ($ this );
227
+ }
228
+
229
+ return $ this ;
230
+ }
231
+
212
232
/**
213
233
* Starts the process and returns after sending the STDIN.
214
234
*
Original file line number Diff line number Diff line change @@ -217,6 +217,28 @@ public function testPTYCommand()
217
217
$ this ->assertEquals ("foo \r\n" , $ process ->getOutput ());
218
218
}
219
219
220
+ /**
221
+ * @group mustRun
222
+ */
223
+ public function testMustRun ()
224
+ {
225
+ $ process = $ this ->getProcess ('echo "foo" ' );
226
+
227
+ $ this ->assertSame ($ process , $ process ->mustRun ());
228
+ $ this ->assertEquals ("foo \n" , $ process ->getOutput ());
229
+ $ this ->assertEquals (0 , $ process ->getExitCode ());
230
+ }
231
+
232
+ /**
233
+ * @expectedException Symfony\Component\Process\Exception\ProcessFailedException
234
+ * @group mustRun
235
+ */
236
+ public function testMustRunThrowsException ()
237
+ {
238
+ $ process = $ this ->getProcess ('exit 1 ' );
239
+ $ process ->mustRun ();
240
+ }
241
+
220
242
public function testExitCodeText ()
221
243
{
222
244
$ process = $ this ->getProcess ('' );
Original file line number Diff line number Diff line change @@ -29,6 +29,24 @@ public function testExitCodeCommandFailed()
29
29
parent ::testExitCodeCommandFailed ();
30
30
}
31
31
32
+ /**
33
+ * @expectedException \Symfony\Component\Process\Exception\RuntimeException
34
+ * @group mustRun
35
+ */
36
+ public function testMustRun ()
37
+ {
38
+ parent ::testMustRun ();
39
+ }
40
+
41
+ /**
42
+ * @expectedException \Symfony\Component\Process\Exception\RuntimeException
43
+ * @group mustRun
44
+ */
45
+ public function testMustRunThrowsException ()
46
+ {
47
+ parent ::testMustRunThrowsException ();
48
+ }
49
+
32
50
/**
33
51
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
34
52
*/
You can’t perform that action at this time.
0 commit comments