5 class ErrorTest extends \PHPUnit_Framework_TestCase
7 public function testConstruct() {
12 $error = new Error('Some error', $attributes);
14 $this->assertSame('Some error', $error->getRawMessage());
15 $this->assertSame($attributes, $error->getAttributes());
16 $this->assertSame(10, $error->getStartLine());
17 $this->assertSame(11, $error->getEndLine());
18 $this->assertSame('Some error on line 10', $error->getMessage());
24 * @depends testConstruct
26 public function testSetMessageAndLine(Error $error) {
27 $error->setRawMessage('Some other error');
28 $this->assertSame('Some other error', $error->getRawMessage());
30 $error->setStartLine(15);
31 $this->assertSame(15, $error->getStartLine());
32 $this->assertSame('Some other error on line 15', $error->getMessage());
35 public function testUnknownLine() {
36 $error = new Error('Some error');
38 $this->assertSame(-1, $error->getStartLine());
39 $this->assertSame(-1, $error->getEndLine());
40 $this->assertSame('Some error on unknown line', $error->getMessage());
43 /** @dataProvider provideTestColumnInfo */
44 public function testColumnInfo($code, $startPos, $endPos, $startColumn, $endColumn) {
45 $error = new Error('Some error', array(
46 'startFilePos' => $startPos,
47 'endFilePos' => $endPos,
50 $this->assertSame(true, $error->hasColumnInfo());
51 $this->assertSame($startColumn, $error->getStartColumn($code));
52 $this->assertSame($endColumn, $error->getEndColumn($code));
56 public function provideTestColumnInfo() {
59 array("<?php foo bar baz", 10, 12, 11, 13),
60 array("<?php\nfoo bar baz", 10, 12, 5, 7),
61 array("<?php foo\nbar baz", 10, 12, 1, 3),
62 array("<?php foo bar\nbaz", 10, 12, 11, 13),
63 array("<?php\r\nfoo bar baz", 11, 13, 5, 7),
65 array("<?php foo bar baz", 14, 16, 15, 17),
66 array("<?php foo bar\nbaz", 14, 16, 1, 3),
67 // Error at string literal
68 array("<?php foo 'bar\nbaz' xyz", 10, 18, 11, 4),
69 array("<?php\nfoo 'bar\nbaz' xyz", 10, 18, 5, 4),
70 array("<?php foo\n'\nbarbaz\n'\nxyz", 10, 19, 1, 1),
71 // Error over full string
72 array("<?php", 0, 4, 1, 5),
73 array("<?\nphp", 0, 5, 1, 3),
77 public function testNoColumnInfo() {
78 $error = new Error('Some error', 3);
80 $this->assertSame(false, $error->hasColumnInfo());
82 $error->getStartColumn('');
83 $this->fail('Expected RuntimeException');
84 } catch (\RuntimeException $e) {
85 $this->assertSame('Error does not have column information', $e->getMessage());
88 $error->getEndColumn('');
89 $this->fail('Expected RuntimeException');
90 } catch (\RuntimeException $e) {
91 $this->assertSame('Error does not have column information', $e->getMessage());
96 * @expectedException \RuntimeException
97 * @expectedExceptionMessage Invalid position information
99 public function testInvalidPosInfo() {
100 $error = new Error('Some error', array(
101 'startFilePos' => 10,
104 $error->getStartColumn('code');