comparison vendor/nikic/php-parser/test/PhpParser/ErrorTest.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 4c8ae668cc8c
children 129ea1e6d783
comparison
equal deleted inserted replaced
12:7a779792577d 13:5fb285c0d0e3
1 <?php 1 <?php declare(strict_types=1);
2 2
3 namespace PhpParser; 3 namespace PhpParser;
4 4
5 class ErrorTest extends \PHPUnit_Framework_TestCase 5 use PHPUnit\Framework\TestCase;
6
7 class ErrorTest extends TestCase
6 { 8 {
7 public function testConstruct() { 9 public function testConstruct() {
8 $attributes = array( 10 $attributes = [
9 'startLine' => 10, 11 'startLine' => 10,
10 'endLine' => 11, 12 'endLine' => 11,
11 ); 13 ];
12 $error = new Error('Some error', $attributes); 14 $error = new Error('Some error', $attributes);
13 15
14 $this->assertSame('Some error', $error->getRawMessage()); 16 $this->assertSame('Some error', $error->getRawMessage());
15 $this->assertSame($attributes, $error->getAttributes()); 17 $this->assertSame($attributes, $error->getAttributes());
16 $this->assertSame(10, $error->getStartLine()); 18 $this->assertSame(10, $error->getStartLine());
40 $this->assertSame('Some error on unknown line', $error->getMessage()); 42 $this->assertSame('Some error on unknown line', $error->getMessage());
41 } 43 }
42 44
43 /** @dataProvider provideTestColumnInfo */ 45 /** @dataProvider provideTestColumnInfo */
44 public function testColumnInfo($code, $startPos, $endPos, $startColumn, $endColumn) { 46 public function testColumnInfo($code, $startPos, $endPos, $startColumn, $endColumn) {
45 $error = new Error('Some error', array( 47 $error = new Error('Some error', [
46 'startFilePos' => $startPos, 48 'startFilePos' => $startPos,
47 'endFilePos' => $endPos, 49 'endFilePos' => $endPos,
48 )); 50 ]);
49 51
50 $this->assertSame(true, $error->hasColumnInfo()); 52 $this->assertTrue($error->hasColumnInfo());
51 $this->assertSame($startColumn, $error->getStartColumn($code)); 53 $this->assertSame($startColumn, $error->getStartColumn($code));
52 $this->assertSame($endColumn, $error->getEndColumn($code)); 54 $this->assertSame($endColumn, $error->getEndColumn($code));
53 55
54 } 56 }
55 57
56 public function provideTestColumnInfo() { 58 public function provideTestColumnInfo() {
57 return array( 59 return [
58 // Error at "bar" 60 // Error at "bar"
59 array("<?php foo bar baz", 10, 12, 11, 13), 61 ["<?php foo bar baz", 10, 12, 11, 13],
60 array("<?php\nfoo bar baz", 10, 12, 5, 7), 62 ["<?php\nfoo bar baz", 10, 12, 5, 7],
61 array("<?php foo\nbar baz", 10, 12, 1, 3), 63 ["<?php foo\nbar baz", 10, 12, 1, 3],
62 array("<?php foo bar\nbaz", 10, 12, 11, 13), 64 ["<?php foo bar\nbaz", 10, 12, 11, 13],
63 array("<?php\r\nfoo bar baz", 11, 13, 5, 7), 65 ["<?php\r\nfoo bar baz", 11, 13, 5, 7],
64 // Error at "baz" 66 // Error at "baz"
65 array("<?php foo bar baz", 14, 16, 15, 17), 67 ["<?php foo bar baz", 14, 16, 15, 17],
66 array("<?php foo bar\nbaz", 14, 16, 1, 3), 68 ["<?php foo bar\nbaz", 14, 16, 1, 3],
67 // Error at string literal 69 // Error at string literal
68 array("<?php foo 'bar\nbaz' xyz", 10, 18, 11, 4), 70 ["<?php foo 'bar\nbaz' xyz", 10, 18, 11, 4],
69 array("<?php\nfoo 'bar\nbaz' xyz", 10, 18, 5, 4), 71 ["<?php\nfoo 'bar\nbaz' xyz", 10, 18, 5, 4],
70 array("<?php foo\n'\nbarbaz\n'\nxyz", 10, 19, 1, 1), 72 ["<?php foo\n'\nbarbaz\n'\nxyz", 10, 19, 1, 1],
71 // Error over full string 73 // Error over full string
72 array("<?php", 0, 4, 1, 5), 74 ["<?php", 0, 4, 1, 5],
73 array("<?\nphp", 0, 5, 1, 3), 75 ["<?\nphp", 0, 5, 1, 3],
74 ); 76 ];
75 } 77 }
76 78
77 public function testNoColumnInfo() { 79 public function testNoColumnInfo() {
78 $error = new Error('Some error', 3); 80 $error = new Error('Some error', 3);
79 81
80 $this->assertSame(false, $error->hasColumnInfo()); 82 $this->assertFalse($error->hasColumnInfo());
81 try { 83 try {
82 $error->getStartColumn(''); 84 $error->getStartColumn('');
83 $this->fail('Expected RuntimeException'); 85 $this->fail('Expected RuntimeException');
84 } catch (\RuntimeException $e) { 86 } catch (\RuntimeException $e) {
85 $this->assertSame('Error does not have column information', $e->getMessage()); 87 $this->assertSame('Error does not have column information', $e->getMessage());
95 /** 97 /**
96 * @expectedException \RuntimeException 98 * @expectedException \RuntimeException
97 * @expectedExceptionMessage Invalid position information 99 * @expectedExceptionMessage Invalid position information
98 */ 100 */
99 public function testInvalidPosInfo() { 101 public function testInvalidPosInfo() {
100 $error = new Error('Some error', array( 102 $error = new Error('Some error', [
101 'startFilePos' => 10, 103 'startFilePos' => 10,
102 'endFilePos' => 11, 104 'endFilePos' => 11,
103 )); 105 ]);
104 $error->getStartColumn('code'); 106 $error->getStartColumn('code');
105 } 107 }
106 } 108 }