|
7 | 7 |
|
8 | 8 | class SyntaxErrorGetNormalizeMessageTest extends UnitTestCase
|
9 | 9 | {
|
10 |
| - public function testInWordInErrorMessage() |
| 10 | + const FILEPATH_MSG_TEMPLATE = "Parse error: unexpected 'Foo' (T_STRING) in %s on line 2"; |
| 11 | + const FILEPATH_MSG_EXPECTED = "Unexpected 'Foo' (T_STRING)"; |
| 12 | + |
| 13 | + /** |
| 14 | + * Test retrieving a normalized error message. |
| 15 | + * |
| 16 | + * @dataProvider dataMessageNormalization |
| 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 testMessageNormalization($message, $expected) |
11 | 24 | {
|
12 |
| - $message = 'Fatal error: \'break\' not in the \'loop\' or \'switch\' context in test.php on line 2'; |
13 | 25 | $error = new SyntaxError('test.php', $message);
|
14 |
| - $this->assertSame('\'break\' not in the \'loop\' or \'switch\' context', $error->getNormalizedMessage()); |
| 26 | + $this->assertSame($expected, $error->getNormalizedMessage()); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Data provider. |
| 31 | + * |
| 32 | + * @return array |
| 33 | + */ |
| 34 | + public function dataMessageNormalization() |
| 35 | + { |
| 36 | + return array( |
| 37 | + 'Strip leading and trailing information' => array( |
| 38 | + 'message' => "Fatal error: 'break' not in the 'loop' or 'switch' context in test.php on line 2", |
| 39 | + 'expected' => "'break' not in the 'loop' or 'switch' context", |
| 40 | + ), |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Test retrieving a normalized error message with variations for the file path. |
| 46 | + * |
| 47 | + * @dataProvider dataFilePathHandling |
| 48 | + * |
| 49 | + * @param string $filePath The file path input to run the test with. |
| 50 | + * @param string $fileName The file name which is expected to be in the error message. |
| 51 | + * |
| 52 | + * @return void |
| 53 | + */ |
| 54 | + public function testFilePathHandling($filePath, $fileName) |
| 55 | + { |
| 56 | + $message = sprintf(self::FILEPATH_MSG_TEMPLATE, $fileName); |
| 57 | + $error = new SyntaxError($filePath, $message); |
| 58 | + $this->assertSame(self::FILEPATH_MSG_EXPECTED, $error->getNormalizedMessage()); |
15 | 59 | }
|
16 | 60 |
|
17 |
| - public function testInWordInErrorMessageAndInFileName() |
| 61 | + /** |
| 62 | + * Data provider. |
| 63 | + * |
| 64 | + * @return array |
| 65 | + */ |
| 66 | + public function dataFilePathHandling() |
18 | 67 | {
|
19 |
| - $message = 'Fatal error: \'break\' not in the \'loop\' or \'switch\' context in test in file.php on line 2'; |
20 |
| - $error = new SyntaxError('test in file.php', $message); |
21 |
| - $this->assertSame('\'break\' not in the \'loop\' or \'switch\' context', $error->getNormalizedMessage()); |
| 68 | + return array( |
| 69 | + 'Plain file name' => array( |
| 70 | + 'filePath' => 'test.php', |
| 71 | + 'fileName' => 'test.php', |
| 72 | + ), |
| 73 | + 'File name containing spaces' => array( |
| 74 | + 'filePath' => 'test in file.php', |
| 75 | + 'fileName' => 'test in file.php', |
| 76 | + ), |
| 77 | + ); |
22 | 78 | }
|
23 | 79 | }
|
0 commit comments