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