annotate 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
rev   line source
Chris@13 1 <?php declare(strict_types=1);
Chris@0 2
Chris@0 3 namespace PhpParser;
Chris@0 4
Chris@13 5 use PHPUnit\Framework\TestCase;
Chris@13 6
Chris@13 7 class ErrorTest extends TestCase
Chris@0 8 {
Chris@0 9 public function testConstruct() {
Chris@13 10 $attributes = [
Chris@0 11 'startLine' => 10,
Chris@0 12 'endLine' => 11,
Chris@13 13 ];
Chris@0 14 $error = new Error('Some error', $attributes);
Chris@0 15
Chris@0 16 $this->assertSame('Some error', $error->getRawMessage());
Chris@0 17 $this->assertSame($attributes, $error->getAttributes());
Chris@0 18 $this->assertSame(10, $error->getStartLine());
Chris@0 19 $this->assertSame(11, $error->getEndLine());
Chris@0 20 $this->assertSame('Some error on line 10', $error->getMessage());
Chris@0 21
Chris@0 22 return $error;
Chris@0 23 }
Chris@0 24
Chris@0 25 /**
Chris@0 26 * @depends testConstruct
Chris@0 27 */
Chris@0 28 public function testSetMessageAndLine(Error $error) {
Chris@0 29 $error->setRawMessage('Some other error');
Chris@0 30 $this->assertSame('Some other error', $error->getRawMessage());
Chris@0 31
Chris@0 32 $error->setStartLine(15);
Chris@0 33 $this->assertSame(15, $error->getStartLine());
Chris@0 34 $this->assertSame('Some other error on line 15', $error->getMessage());
Chris@0 35 }
Chris@0 36
Chris@0 37 public function testUnknownLine() {
Chris@0 38 $error = new Error('Some error');
Chris@0 39
Chris@0 40 $this->assertSame(-1, $error->getStartLine());
Chris@0 41 $this->assertSame(-1, $error->getEndLine());
Chris@0 42 $this->assertSame('Some error on unknown line', $error->getMessage());
Chris@0 43 }
Chris@0 44
Chris@0 45 /** @dataProvider provideTestColumnInfo */
Chris@0 46 public function testColumnInfo($code, $startPos, $endPos, $startColumn, $endColumn) {
Chris@13 47 $error = new Error('Some error', [
Chris@0 48 'startFilePos' => $startPos,
Chris@0 49 'endFilePos' => $endPos,
Chris@13 50 ]);
Chris@0 51
Chris@13 52 $this->assertTrue($error->hasColumnInfo());
Chris@0 53 $this->assertSame($startColumn, $error->getStartColumn($code));
Chris@0 54 $this->assertSame($endColumn, $error->getEndColumn($code));
Chris@0 55
Chris@0 56 }
Chris@0 57
Chris@0 58 public function provideTestColumnInfo() {
Chris@13 59 return [
Chris@0 60 // Error at "bar"
Chris@13 61 ["<?php foo bar baz", 10, 12, 11, 13],
Chris@13 62 ["<?php\nfoo bar baz", 10, 12, 5, 7],
Chris@13 63 ["<?php foo\nbar baz", 10, 12, 1, 3],
Chris@13 64 ["<?php foo bar\nbaz", 10, 12, 11, 13],
Chris@13 65 ["<?php\r\nfoo bar baz", 11, 13, 5, 7],
Chris@0 66 // Error at "baz"
Chris@13 67 ["<?php foo bar baz", 14, 16, 15, 17],
Chris@13 68 ["<?php foo bar\nbaz", 14, 16, 1, 3],
Chris@0 69 // Error at string literal
Chris@13 70 ["<?php foo 'bar\nbaz' xyz", 10, 18, 11, 4],
Chris@13 71 ["<?php\nfoo 'bar\nbaz' xyz", 10, 18, 5, 4],
Chris@13 72 ["<?php foo\n'\nbarbaz\n'\nxyz", 10, 19, 1, 1],
Chris@0 73 // Error over full string
Chris@13 74 ["<?php", 0, 4, 1, 5],
Chris@13 75 ["<?\nphp", 0, 5, 1, 3],
Chris@13 76 ];
Chris@0 77 }
Chris@0 78
Chris@0 79 public function testNoColumnInfo() {
Chris@0 80 $error = new Error('Some error', 3);
Chris@0 81
Chris@13 82 $this->assertFalse($error->hasColumnInfo());
Chris@0 83 try {
Chris@0 84 $error->getStartColumn('');
Chris@0 85 $this->fail('Expected RuntimeException');
Chris@0 86 } catch (\RuntimeException $e) {
Chris@0 87 $this->assertSame('Error does not have column information', $e->getMessage());
Chris@0 88 }
Chris@0 89 try {
Chris@0 90 $error->getEndColumn('');
Chris@0 91 $this->fail('Expected RuntimeException');
Chris@0 92 } catch (\RuntimeException $e) {
Chris@0 93 $this->assertSame('Error does not have column information', $e->getMessage());
Chris@0 94 }
Chris@0 95 }
Chris@0 96
Chris@0 97 /**
Chris@0 98 * @expectedException \RuntimeException
Chris@0 99 * @expectedExceptionMessage Invalid position information
Chris@0 100 */
Chris@0 101 public function testInvalidPosInfo() {
Chris@13 102 $error = new Error('Some error', [
Chris@0 103 'startFilePos' => 10,
Chris@0 104 'endFilePos' => 11,
Chris@13 105 ]);
Chris@0 106 $error->getStartColumn('code');
Chris@0 107 }
Chris@0 108 }