TokenizerLintingResultTest.php 1.8 KB

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