TokenizerLintingResultTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\TokenizerLintingResult;
  14. use PhpCsFixer\Tests\TestCase;
  15. /**
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Linter\TokenizerLintingResult
  19. */
  20. final class TokenizerLintingResultTest extends TestCase
  21. {
  22. /**
  23. * @doesNotPerformAssertions
  24. */
  25. public function testTokenizerLintingResultOK(): void
  26. {
  27. $result = new TokenizerLintingResult();
  28. $result->check();
  29. }
  30. public function testTokenizerLintingResultFailParseError(): void
  31. {
  32. $error = new \ParseError('syntax error, unexpected end of file, expecting \'{\'', 567);
  33. $line = __LINE__ - 1;
  34. $result = new TokenizerLintingResult($error);
  35. $this->expectException(
  36. \PhpCsFixer\Linter\LintingException::class
  37. );
  38. $this->expectExceptionMessage(
  39. sprintf('Parse error: syntax error, unexpected end of file, expecting \'{\' on line %d.', $line)
  40. );
  41. $this->expectExceptionCode(
  42. 567
  43. );
  44. $result->check();
  45. }
  46. public function testTokenizerLintingResultFailCompileError(): void
  47. {
  48. $error = new \CompileError('Multiple access type modifiers are not allowed');
  49. $line = __LINE__ - 1;
  50. $result = new TokenizerLintingResult($error);
  51. $this->expectException(
  52. \PhpCsFixer\Linter\LintingException::class
  53. );
  54. $this->expectExceptionMessage(
  55. sprintf('Fatal error: Multiple access type modifiers are not allowed on line %d.', $line)
  56. );
  57. $result->check();
  58. }
  59. }