|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PHP_Parallel_Lint\PhpParallelLint\Tests\Unit\Errors; |
| 4 | + |
| 5 | +use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError; |
| 6 | +use PHP_Parallel_Lint\PhpParallelLint\Tests\UnitTestCase; |
| 7 | + |
| 8 | +/** |
| 9 | + * @covers \PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError::translateTokens |
| 10 | + */ |
| 11 | +class SyntaxErrorTranslateTokensTest extends UnitTestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * Test retrieving a normalized error message with token translations on. |
| 15 | + * |
| 16 | + * @dataProvider dataTranslateTokens |
| 17 | + * |
| 18 | + * @param string $message The message input to run the test with. |
| 19 | + * @param string $expected The expected method return value. |
| 20 | + * |
| 21 | + * @return void |
| 22 | + */ |
| 23 | + public function testTranslateTokens($message, $expected) |
| 24 | + { |
| 25 | + $error = new SyntaxError('test.php', $message); |
| 26 | + $this->assertSame($expected, $error->getNormalizedMessage(true)); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Data provider. |
| 31 | + * |
| 32 | + * @return array |
| 33 | + */ |
| 34 | + public function dataTranslateTokens() |
| 35 | + { |
| 36 | + return array( |
| 37 | + 'No token name in message' => array( |
| 38 | + 'message' => 'Methods with the same name as their class will not be constructors in a future version of PHP', |
| 39 | + 'expected' => 'Methods with the same name as their class will not be constructors in a future version of PHP', |
| 40 | + ), |
| 41 | + 'Non-existent token name in message (shouldn\'t be possible)' => array( |
| 42 | + 'message' => 'Unexpected T_1H2, expecting T_STRING', |
| 43 | + 'expected' => 'Unexpected T_1H2, expecting T_STRING', |
| 44 | + ), |
| 45 | + 'Token names in message, but not in translation list' => array( |
| 46 | + // phpcs:disable Generic.Files.LineLength.TooLong |
| 47 | + 'message' => 'Unexpected \'\' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)', |
| 48 | + 'expected' => 'Unexpected \'\' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)', |
| 49 | + // phpcs:enable Generic.Files.LineLength |
| 50 | + ), |
| 51 | + 'PHP 5.3-style message with token name without PHP native translation [1]' => array( |
| 52 | + 'message' => 'Unexpected T_FILE, expecting T_STRING', |
| 53 | + 'expected' => 'Unexpected __FILE__ (T_FILE), expecting T_STRING', |
| 54 | + ), |
| 55 | + 'PHP 5.3-style message with token name without PHP native translation [2]' => array( |
| 56 | + 'message' => 'Unexpected T_INC', |
| 57 | + 'expected' => 'Unexpected ++ (T_INC)', |
| 58 | + ), |
| 59 | + 'Message with multiple tokens without PHP native translation' => array( |
| 60 | + 'message' => 'Unexpected T_INC, T_IS_IDENTICAL, T_OBJECT_OPERATOR, T_START_HEREDOC', |
| 61 | + 'expected' => 'Unexpected ++ (T_INC), === (T_IS_IDENTICAL), -> (T_OBJECT_OPERATOR), <<< (T_START_HEREDOC)', |
| 62 | + ), |
| 63 | + ); |
| 64 | + } |
| 65 | +} |
0 commit comments