Skip to content

Commit c592842

Browse files
jrfnlgrogy
authored andcommitted
SyntaxErrorGetNormalizeMessageTest: add some additional test cases
Including documenting that a `Deprecated:` prefix will not be removed.
1 parent 40729e9 commit c592842

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

tests/Unit/Errors/SyntaxErrorGetNormalizeMessageTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SyntaxErrorGetNormalizeMessageTest extends UnitTestCase
2020
*
2121
* @return void
2222
*/
23-
public function testMessageNormalization($message, $expected)
23+
public function testMessageNormalizationWithoutTokenTranslation($message, $expected)
2424
{
2525
$error = new SyntaxError('test.php', $message);
2626
$this->assertSame($expected, $error->getNormalizedMessage());
@@ -34,13 +34,35 @@ public function testMessageNormalization($message, $expected)
3434
public function dataMessageNormalization()
3535
{
3636
return array(
37-
'Strip leading and trailing information' => array(
37+
'Strip leading and trailing information - fatal error' => array(
3838
'message' => "Fatal error: 'break' not in the 'loop' or 'switch' context in test.php on line 2",
3939
'expected' => "'break' not in the 'loop' or 'switch' context",
4040
),
41+
'Strip leading and trailing information - parse error' => array(
42+
'message' => "Parse error: unexpected 'Foo' (T_STRING) in test.php on line 2",
43+
'expected' => "Unexpected 'Foo' (T_STRING)", // Also verifies ucfirst() call is being made.
44+
),
45+
'Strip trailing information, not leading - deprecation' => array(
46+
'message' => "Deprecated: The (real) cast is deprecated, use (float) instead in test.php on line 2",
47+
'expected' => "Deprecated: The (real) cast is deprecated, use (float) instead",
48+
),
4149
);
4250
}
4351

52+
/**
53+
* Test retrieving a normalized error message with token translation.
54+
*
55+
* @return void
56+
*/
57+
public function testMessageNormalizationWithTokenTranslation()
58+
{
59+
$message = 'Parse error: unexpected T_FILE, expecting T_STRING in test.php on line 2';
60+
$expected = 'Unexpected __FILE__ (T_FILE), expecting T_STRING';
61+
62+
$error = new SyntaxError('test.php', $message);
63+
$this->assertSame($expected, $error->getNormalizedMessage(true));
64+
}
65+
4466
/**
4567
* Test retrieving a normalized error message with variations for the file path.
4668
*

0 commit comments

Comments
 (0)