Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2ff1870

Browse filesBrowse files
committed
adds convenience method mustRun
1 parent 53441aa commit 2ff1870
Copy full SHA for 2ff1870

File tree

Expand file treeCollapse file tree

4 files changed

+61
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+61
-0
lines changed
Open diff view settings
Collapse file

‎src/Symfony/Component/Process/CHANGELOG.md‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* added the ability to define an idle timeout
88
* added support for PTY mode
9+
* added the convenience method "mustRun"
910

1011
2.3.0
1112
-----
Collapse file

‎src/Symfony/Component/Process/Process.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Process.php
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Process\Exception\InvalidArgumentException;
1515
use Symfony\Component\Process\Exception\LogicException;
16+
use Symfony\Component\Process\Exception\ProcessFailedException;
1617
use Symfony\Component\Process\Exception\ProcessTimedOutException;
1718
use Symfony\Component\Process\Exception\RuntimeException;
1819

@@ -209,6 +210,25 @@ public function run($callback = null)
209210
return $this->wait($callback);
210211
}
211212

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+
212232
/**
213233
* Starts the process and returns after sending the STDIN.
214234
*
Collapse file

‎src/Symfony/Component/Process/Tests/AbstractProcessTest.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Tests/AbstractProcessTest.php
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,28 @@ public function testPTYCommand()
217217
$this->assertEquals("foo\r\n", $process->getOutput());
218218
}
219219

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+
220242
public function testExitCodeText()
221243
{
222244
$process = $this->getProcess('');
Collapse file

‎src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php‎

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Tests/SigchildDisabledProcessTest.php
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ public function testExitCodeCommandFailed()
2929
parent::testExitCodeCommandFailed();
3030
}
3131

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+
3250
/**
3351
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
3452
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.