ProcessLintingResultTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Linter;
  13. use PhpCsFixer\Linter\LintingException;
  14. use PhpCsFixer\Linter\ProcessLintingResult;
  15. use PhpCsFixer\Tests\TestCase;
  16. use Symfony\Component\Process\Process;
  17. /**
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\Linter\ProcessLintingResult
  21. */
  22. final class ProcessLintingResultTest extends TestCase
  23. {
  24. /**
  25. * @doesNotPerformAssertions
  26. */
  27. public function testCheckOK(): void
  28. {
  29. $process = $this->prophesize();
  30. $process->willExtend(Process::class);
  31. $process
  32. ->wait()
  33. ->willReturn(0)
  34. ;
  35. $process
  36. ->isSuccessful()
  37. ->willReturn(true)
  38. ;
  39. $result = new ProcessLintingResult($process->reveal());
  40. $result->check();
  41. }
  42. public function testCheckFail(): void
  43. {
  44. $process = $this->prophesize();
  45. $process->willExtend(Process::class);
  46. $process
  47. ->wait()
  48. ->willReturn(0)
  49. ;
  50. $process
  51. ->isSuccessful()
  52. ->willReturn(false)
  53. ;
  54. $process
  55. ->getErrorOutput()
  56. ->willReturn('PHP Parse error: syntax error, unexpected end of file, expecting \'{\' in test.php on line 4')
  57. ;
  58. $process
  59. ->getExitCode()
  60. ->willReturn(123)
  61. ;
  62. $result = new ProcessLintingResult($process->reveal(), 'test.php');
  63. $this->expectException(LintingException::class);
  64. $this->expectExceptionMessage('Parse error: syntax error, unexpected end of file, expecting \'{\' on line 4.');
  65. $this->expectExceptionCode(123);
  66. $result->check();
  67. }
  68. }