Skip to content

Commit cd6745e

Browse files
committed
Tests: add perfunctory tests for the remaining methods in SyntaxError
1 parent 8f1056e commit cd6745e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace PHP_Parallel_Lint\PhpParallelLint\Tests\Unit\Errors;
4+
5+
use PHP_Parallel_Lint\PhpParallelLint\Blame;
6+
use PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError;
7+
use PHP_Parallel_Lint\PhpParallelLint\Tests\UnitTestCase;
8+
9+
class SyntaxErrorOtherTest extends UnitTestCase
10+
{
11+
/**
12+
* Test setting and getting the blame.
13+
*
14+
* @covers \PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError::setBlame
15+
* @covers \PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError::getBlame
16+
*
17+
* @return void
18+
*/
19+
public function testGetSetBlame()
20+
{
21+
$blame = new Blame();
22+
$error = new SyntaxError('test.php', 'message');
23+
24+
$error->setBlame($blame);
25+
$this->assertSame($blame, $error->getBlame());
26+
}
27+
28+
/**
29+
* Test retrieving the error in Json serialized format.
30+
*
31+
* @covers \PHP_Parallel_Lint\PhpParallelLint\Errors\SyntaxError::jsonSerialize
32+
*
33+
* @requires PHP 5.4
34+
*
35+
* @return void
36+
*/
37+
public function testJsonSerialize()
38+
{
39+
// phpcs:ignore Generic.Files.LineLength.MaxExceeded
40+
$expected = '{"type":"syntaxError","file":"path\/to\/file.php","line":2,"message":"Parse error: unexpected \'Foo\' (T_STRING) in file.php on line 2","normalizeMessage":"Unexpected \'Foo\' (T_STRING)","blame":null}';
41+
42+
$error = new SyntaxError('path/to/file.php', "Parse error: unexpected 'Foo' (T_STRING) in file.php on line 2");
43+
$this->assertJsonStringEqualsJsonString($expected, json_encode($error));
44+
}
45+
}

0 commit comments

Comments
 (0)