Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / nikic / php-parser / test / PhpParser / JsonDecoderTest.php
1 <?php declare(strict_types=1);
2
3 namespace PhpParser;
4
5 use PHPUnit\Framework\TestCase;
6
7 class JsonDecoderTest extends TestCase
8 {
9     public function testRoundTrip() {
10         $code = <<<'PHP'
11 <?php
12 // comment
13 /** doc comment */
14 function functionName(&$a = 0, $b = 1.0) {
15     echo 'Foo';
16 }
17 PHP;
18
19         $parser = new Parser\Php7(new Lexer());
20         $stmts = $parser->parse($code);
21         $json = json_encode($stmts);
22
23         $jsonDecoder = new JsonDecoder();
24         $decodedStmts = $jsonDecoder->decode($json);
25         $this->assertEquals($stmts, $decodedStmts);
26     }
27
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);
34     }
35
36     public function provideTestDecodingError() {
37         return [
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"'],
43         ];
44     }
45 }