X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fnikic%2Fphp-parser%2Ftest%2FPhpParser%2FErrorTest.php;fp=vendor%2Fnikic%2Fphp-parser%2Ftest%2FPhpParser%2FErrorTest.php;h=59e880c308a3bf9ed29350c5761159c4ee18b70e;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/nikic/php-parser/test/PhpParser/ErrorTest.php b/vendor/nikic/php-parser/test/PhpParser/ErrorTest.php new file mode 100644 index 000000000..59e880c30 --- /dev/null +++ b/vendor/nikic/php-parser/test/PhpParser/ErrorTest.php @@ -0,0 +1,106 @@ + 10, + 'endLine' => 11, + ); + $error = new Error('Some error', $attributes); + + $this->assertSame('Some error', $error->getRawMessage()); + $this->assertSame($attributes, $error->getAttributes()); + $this->assertSame(10, $error->getStartLine()); + $this->assertSame(11, $error->getEndLine()); + $this->assertSame('Some error on line 10', $error->getMessage()); + + return $error; + } + + /** + * @depends testConstruct + */ + public function testSetMessageAndLine(Error $error) { + $error->setRawMessage('Some other error'); + $this->assertSame('Some other error', $error->getRawMessage()); + + $error->setStartLine(15); + $this->assertSame(15, $error->getStartLine()); + $this->assertSame('Some other error on line 15', $error->getMessage()); + } + + public function testUnknownLine() { + $error = new Error('Some error'); + + $this->assertSame(-1, $error->getStartLine()); + $this->assertSame(-1, $error->getEndLine()); + $this->assertSame('Some error on unknown line', $error->getMessage()); + } + + /** @dataProvider provideTestColumnInfo */ + public function testColumnInfo($code, $startPos, $endPos, $startColumn, $endColumn) { + $error = new Error('Some error', array( + 'startFilePos' => $startPos, + 'endFilePos' => $endPos, + )); + + $this->assertSame(true, $error->hasColumnInfo()); + $this->assertSame($startColumn, $error->getStartColumn($code)); + $this->assertSame($endColumn, $error->getEndColumn($code)); + + } + + public function provideTestColumnInfo() { + return array( + // Error at "bar" + array("assertSame(false, $error->hasColumnInfo()); + try { + $error->getStartColumn(''); + $this->fail('Expected RuntimeException'); + } catch (\RuntimeException $e) { + $this->assertSame('Error does not have column information', $e->getMessage()); + } + try { + $error->getEndColumn(''); + $this->fail('Expected RuntimeException'); + } catch (\RuntimeException $e) { + $this->assertSame('Error does not have column information', $e->getMessage()); + } + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage Invalid position information + */ + public function testInvalidPosInfo() { + $error = new Error('Some error', array( + 'startFilePos' => 10, + 'endFilePos' => 11, + )); + $error->getStartColumn('code'); + } +}