comparison vendor/nikic/php-parser/test/PhpParser/JsonDecoderTest.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
12:7a779792577d 13:5fb285c0d0e3
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 }