1 <?php declare(strict_types=1);
5 use PHPUnit\Framework\TestCase;
7 class JsonDecoderTest extends TestCase
9 public function testRoundTrip() {
14 function functionName(&$a = 0, $b = 1.0) {
19 $parser = new Parser\Php7(new Lexer());
20 $stmts = $parser->parse($code);
21 $json = json_encode($stmts);
23 $jsonDecoder = new JsonDecoder();
24 $decodedStmts = $jsonDecoder->decode($json);
25 $this->assertEquals($stmts, $decodedStmts);
28 /** @dataProvider provideTestDecodingError */
29 public function testDecodingError($json, $expectedMessage) {
30 $jsonDecoder = new JsonDecoder();
31 $this->expectException(\RuntimeException::class);
32 $this->expectExceptionMessage($expectedMessage);
33 $jsonDecoder->decode($json);
36 public function provideTestDecodingError() {
38 ['???', 'JSON decoding error: Syntax error'],
39 ['{"nodeType":123}', 'Node type must be a string'],
40 ['{"nodeType":"Name","attributes":123}', 'Attributes must be an array'],
41 ['{"nodeType":"Comment"}', 'Comment must have text'],
42 ['{"nodeType":"xxx"}', 'Unknown node type "xxx"'],