Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  Use createMock() and use import instead of FQCN
  • Loading branch information
nicolas-grekas committed Jan 27, 2021
2 parents 9ee12c5 + 7e950b6 commit d279ae7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
7 changes: 4 additions & 3 deletions Tests/ProcessFailedExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

/**
* @author Sebastian Marek <[email protected]>
Expand All @@ -24,7 +25,7 @@ class ProcessFailedExceptionTest extends TestCase
*/
public function testProcessFailedExceptionThrowsException()
{
$process = $this->getMockBuilder(\Symfony\Component\Process\Process::class)->setMethods(['isSuccessful'])->setConstructorArgs([['php']])->getMock();
$process = $this->getMockBuilder(Process::class)->setMethods(['isSuccessful'])->setConstructorArgs([['php']])->getMock();
$process->expects($this->once())
->method('isSuccessful')
->willReturn(true);
Expand All @@ -48,7 +49,7 @@ public function testProcessFailedExceptionPopulatesInformationFromProcessOutput(
$errorOutput = 'FATAL: Unexpected error';
$workingDirectory = getcwd();

$process = $this->getMockBuilder(\Symfony\Component\Process\Process::class)->setMethods(['isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'])->setConstructorArgs([[$cmd]])->getMock();
$process = $this->getMockBuilder(Process::class)->setMethods(['isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'])->setConstructorArgs([[$cmd]])->getMock();
$process->expects($this->once())
->method('isSuccessful')
->willReturn(false);
Expand Down Expand Up @@ -96,7 +97,7 @@ public function testDisabledOutputInFailedExceptionDoesNotPopulateOutput()
$exitText = 'General error';
$workingDirectory = getcwd();

$process = $this->getMockBuilder(\Symfony\Component\Process\Process::class)->setMethods(['isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'])->setConstructorArgs([[$cmd]])->getMock();
$process = $this->getMockBuilder(Process::class)->setMethods(['isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'])->setConstructorArgs([[$cmd]])->getMock();
$process->expects($this->once())
->method('isSuccessful')
->willReturn(false);
Expand Down
17 changes: 10 additions & 7 deletions Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
namespace Symfony\Component\Process\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Exception\InvalidArgumentException;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessSignaledException;
use Symfony\Component\Process\Exception\ProcessTimedOutException;
use Symfony\Component\Process\Exception\RuntimeException;
use Symfony\Component\Process\InputStream;
Expand Down Expand Up @@ -78,13 +81,13 @@ public function testThatProcessDoesNotThrowWarningDuringRun()

public function testNegativeTimeoutFromConstructor()
{
$this->expectException(\Symfony\Component\Process\Exception\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$this->getProcess('', null, null, null, -1);
}

public function testNegativeTimeoutFromSetter()
{
$this->expectException(\Symfony\Component\Process\Exception\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$p = $this->getProcess('');
$p->setTimeout(-1);
}
Expand Down Expand Up @@ -292,7 +295,7 @@ public function testSetInputWhileRunningThrowsAnException()
*/
public function testInvalidInput($value)
{
$this->expectException(\Symfony\Component\Process\Exception\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('"Symfony\Component\Process\Process::setInput" only accepts strings, Traversable objects or stream resources.');
$process = $this->getProcess('foo');
$process->setInput($value);
Expand Down Expand Up @@ -555,7 +558,7 @@ public function testSuccessfulMustRunHasCorrectExitCode()

public function testMustRunThrowsException()
{
$this->expectException(\Symfony\Component\Process\Exception\ProcessFailedException::class);
$this->expectException(ProcessFailedException::class);
$process = $this->getProcess('exit 1');
$process->mustRun();
}
Expand Down Expand Up @@ -707,7 +710,7 @@ public function testProcessIsSignaledIfStopped()

public function testProcessThrowsExceptionWhenExternallySignaled()
{
$this->expectException(\Symfony\Component\Process\Exception\ProcessSignaledException::class);
$this->expectException(ProcessSignaledException::class);
$this->expectExceptionMessage('The process has been signaled with signal "9".');
if (!\function_exists('posix_kill')) {
$this->markTestSkipped('Function posix_kill is required.');
Expand Down Expand Up @@ -1485,15 +1488,15 @@ public function testPreparedCommandWithQuoteInIt()

public function testPreparedCommandWithMissingValue()
{
$this->expectException(\Symfony\Component\Process\Exception\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Command line is missing a value for parameter "abc": echo "${:abc}"');
$p = Process::fromShellCommandline('echo "${:abc}"');
$p->run(null, ['bcd' => 'BCD']);
}

public function testPreparedCommandWithNoValues()
{
$this->expectException(\Symfony\Component\Process\Exception\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Command line is missing a value for parameter "abc": echo "${:abc}"');
$p = Process::fromShellCommandline('echo "${:abc}"');
$p->run(null, []);
Expand Down

0 comments on commit d279ae7

Please sign in to comment.