ProcessLintingResultTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. public function testCheckOK(): void
  25. {
  26. $process = new class([]) extends Process {
  27. public function wait(?callable $callback = null): int
  28. {
  29. return 0;
  30. }
  31. public function isSuccessful(): bool
  32. {
  33. return true;
  34. }
  35. };
  36. $result = new ProcessLintingResult($process);
  37. $result->check();
  38. $this->expectNotToPerformAssertions();
  39. }
  40. public function testCheckFail(): void
  41. {
  42. $process = new class([]) extends Process {
  43. public function wait(?callable $callback = null): int
  44. {
  45. return 0;
  46. }
  47. public function isSuccessful(): bool
  48. {
  49. return false;
  50. }
  51. public function getErrorOutput(): string
  52. {
  53. return 'PHP Parse error: syntax error, unexpected end of file, expecting \'{\' in test.php on line 4';
  54. }
  55. public function getExitCode(): int
  56. {
  57. return 123;
  58. }
  59. };
  60. $result = new ProcessLintingResult($process, 'test.php');
  61. $this->expectException(LintingException::class);
  62. $this->expectExceptionMessage('Parse error: syntax error, unexpected end of file, expecting \'{\' on line 4.');
  63. $this->expectExceptionCode(123);
  64. $result->check();
  65. }
  66. }