ProcessFailedExceptionTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Process\Tests;
  11. use Symfony\Component\Process\Exception\ProcessFailedException;
  12. /**
  13. * @author Sebastian Marek <proofek@gmail.com>
  14. */
  15. class ProcessFailedExceptionTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * tests ProcessFailedException throws exception if the process was successful
  19. */
  20. public function testProcessFailedExceptionThrowsException()
  21. {
  22. $process = $this->getMock(
  23. 'Symfony\Component\Process\Process',
  24. array('isSuccessful'),
  25. array('php')
  26. );
  27. $process->expects($this->once())
  28. ->method('isSuccessful')
  29. ->will($this->returnValue(true));
  30. $this->setExpectedException(
  31. '\InvalidArgumentException',
  32. 'Expected a failed process, but the given process was successful.'
  33. );
  34. new ProcessFailedException($process);
  35. }
  36. /**
  37. * tests ProcessFailedException uses information from process output
  38. * to generate exception message
  39. */
  40. public function testProcessFailedExceptionPopulatesInformationFromProcessOutput()
  41. {
  42. $cmd = 'php';
  43. $output = "Command output";
  44. $errorOutput = "FATAL: Unexpected error";
  45. $process = $this->getMock(
  46. 'Symfony\Component\Process\Process',
  47. array('isSuccessful', 'getOutput', 'getErrorOutput'),
  48. array($cmd)
  49. );
  50. $process->expects($this->once())
  51. ->method('isSuccessful')
  52. ->will($this->returnValue(false));
  53. $process->expects($this->once())
  54. ->method('getOutput')
  55. ->will($this->returnValue($output));
  56. $process->expects($this->once())
  57. ->method('getErrorOutput')
  58. ->will($this->returnValue($errorOutput));
  59. $exception = new ProcessFailedException($process);
  60. $this->assertEquals(
  61. "The command \"$cmd\" failed.\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
  62. $exception->getMessage()
  63. );
  64. }
  65. }