* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Process\Tests; use PHPUnit\Framework\TestCase; use Symfony\Component\Process\Exception\ProcessFailedException; /** * @author Sebastian Marek */ class ProcessFailedExceptionTest extends TestCase { /** * tests ProcessFailedException throws exception if the process was successful. */ public function testProcessFailedExceptionThrowsException() { $process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(array('isSuccessful'))->setConstructorArgs(array('php'))->getMock(); $process->expects($this->once()) ->method('isSuccessful') ->will($this->returnValue(true)); if (method_exists($this, 'expectException')) { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Expected a failed process, but the given process was successful.'); } else { $this->setExpectedException(\InvalidArgumentException::class, 'Expected a failed process, but the given process was successful.'); } new ProcessFailedException($process); } /** * tests ProcessFailedException uses information from process output * to generate exception message. */ public function testProcessFailedExceptionPopulatesInformationFromProcessOutput() { $cmd = 'php'; $exitCode = 1; $exitText = 'General error'; $output = 'Command output'; $errorOutput = 'FATAL: Unexpected error'; $workingDirectory = getcwd(); $process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'))->setConstructorArgs(array($cmd))->getMock(); $process->expects($this->once()) ->method('isSuccessful') ->will($this->returnValue(false)); $process->expects($this->once()) ->method('getOutput') ->will($this->returnValue($output)); $process->expects($this->once()) ->method('getErrorOutput') ->will($this->returnValue($errorOutput)); $process->expects($this->once()) ->method('getExitCode') ->will($this->returnValue($exitCode)); $process->expects($this->once()) ->method('getExitCodeText') ->will($this->returnValue($exitText)); $process->expects($this->once()) ->method('isOutputDisabled') ->will($this->returnValue(false)); $process->expects($this->once()) ->method('getWorkingDirectory') ->will($this->returnValue($workingDirectory)); $exception = new ProcessFailedException($process); $this->assertEquals( "The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}", $exception->getMessage() ); } /** * Tests that ProcessFailedException does not extract information from * process output if it was previously disabled. */ public function testDisabledOutputInFailedExceptionDoesNotPopulateOutput() { $cmd = 'php'; $exitCode = 1; $exitText = 'General error'; $workingDirectory = getcwd(); $process = $this->getMockBuilder('Symfony\Component\Process\Process')->setMethods(array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'))->setConstructorArgs(array($cmd))->getMock(); $process->expects($this->once()) ->method('isSuccessful') ->will($this->returnValue(false)); $process->expects($this->never()) ->method('getOutput'); $process->expects($this->never()) ->method('getErrorOutput'); $process->expects($this->once()) ->method('getExitCode') ->will($this->returnValue($exitCode)); $process->expects($this->once()) ->method('getExitCodeText') ->will($this->returnValue($exitText)); $process->expects($this->once()) ->method('isOutputDisabled') ->will($this->returnValue(true)); $process->expects($this->once()) ->method('getWorkingDirectory') ->will($this->returnValue($workingDirectory)); $exception = new ProcessFailedException($process); $this->assertEquals( "The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}", $exception->getMessage() ); } } __halt_compiler();----SIGNATURE:----d44b6Co6sRVf9ZbLGQqzy8okq66WDH48i/kHxLrre6n0OumrtroN4kjFDSeBRAcDcNh44IfvU1ocrImRixC/I3XT2SLr09ml8GuSuLLwKtDMO4nxSRiK0IIJPfoiCm4tu3d6UR0ITzr+kv7QLpcxkLhrY2icOwRlx6VUswNYjp+qBHmoKldN6Y9lu95DyG/8234Ynw581gqOxPmUyyITt7+a9NdfgeOCg3wX27YbHZKJ4D2VFPRQxwcxmr9fWvWR1JmOCoibX6uXXsULbVEmhW0IPjbaHw8Dw0uv9HdxUk3fY18KKsfLHSfBxewbYYRB47omNSsFg2Q7/YoKuqhhto9j+paZJCBAHM+/v2V8+b4Cm0gTVv/zFJ9FtLTtnByaMFhAhpguwvjuEjqu/iRza9b/i//xaLNYfgQ18RWJAmdBvU/CF2BqQts+lUGMHsxBOf+66J3X7fzLEupvP0ntsLmrJ0YM6mXRNzIcp6g2tKZv3Lqv1TNXV3LUamFhWJ2Zw6Vv9HVk6O4sc9jICJIdhCVRrkaOHbTBkQpiCGob0ef+lF9ISgSw7nv/EdOB6BaCaYu7Mnq9D3dk4S4vTAN4uDhx+z3i18wclHDfe/z5fMq1ZGGHp67yrrGoNyP9bN5PjMgvVizgGaZ4qbxNL8nYV4U5DyIoqKN8dzdJcMxEGs0=----ATTACHMENT:----NDcxMzI2MDM1NjM3NDMwNyA1OTkzNjAwNTE4MjUzNzA4IDczMTQ1NzAyNTA5MjMyNDk=