2011-11-27 21:43:27 +01:00
|
|
|
<?php
|
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser;
|
|
|
|
|
|
|
|
class ErrorTest extends \PHPUnit_Framework_TestCase
|
2011-11-27 21:43:27 +01:00
|
|
|
{
|
|
|
|
public function testConstruct() {
|
2014-02-06 14:44:16 +01:00
|
|
|
$error = new Error('Some error', 10);
|
2011-11-27 21:43:27 +01:00
|
|
|
|
2014-09-30 20:38:09 +02:00
|
|
|
$this->assertSame('Some error', $error->getRawMessage());
|
|
|
|
$this->assertSame(10, $error->getRawLine());
|
|
|
|
$this->assertSame('Some error on line 10', $error->getMessage());
|
2011-11-27 21:43:27 +01:00
|
|
|
|
|
|
|
return $error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testConstruct
|
|
|
|
*/
|
2014-02-06 14:44:16 +01:00
|
|
|
public function testSetMessageAndLine(Error $error) {
|
2011-11-27 21:43:27 +01:00
|
|
|
$error->setRawMessage('Some other error');
|
|
|
|
$error->setRawLine(15);
|
|
|
|
|
2014-09-30 20:38:09 +02:00
|
|
|
$this->assertSame('Some other error', $error->getRawMessage());
|
|
|
|
$this->assertSame(15, $error->getRawLine());
|
|
|
|
$this->assertSame('Some other error on line 15', $error->getMessage());
|
2011-11-27 21:43:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUnknownLine() {
|
2014-02-06 14:44:16 +01:00
|
|
|
$error = new Error('Some error');
|
2011-11-27 21:43:27 +01:00
|
|
|
|
2014-09-30 20:38:09 +02:00
|
|
|
$this->assertSame(-1, $error->getRawLine());
|
|
|
|
$this->assertSame('Some error on unknown line', $error->getMessage());
|
2011-11-27 21:43:27 +01:00
|
|
|
}
|
2015-04-14 20:31:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testConstruct
|
|
|
|
*/
|
|
|
|
public function testColumnNumbers() {
|
|
|
|
|
|
|
|
$faultyCode = "<?php \$foo = bar baz; ?>";
|
|
|
|
|
|
|
|
$tokens = token_get_all($faultyCode);
|
|
|
|
|
|
|
|
$error = new Error('Some error', 1, $tokens, 5);
|
|
|
|
|
|
|
|
$this->assertSame(true, $error->hasTokenAttributes());
|
|
|
|
$this->assertSame(13, $error->getBeginColumn());
|
|
|
|
$this->assertSame(16, $error->getEndColumn());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testConstruct
|
|
|
|
*/
|
|
|
|
public function testTokenInformationMissing(){
|
|
|
|
|
|
|
|
$error = new Error('Some error', 3);
|
|
|
|
|
|
|
|
$this->assertSame(false, $error->hasTokenAttributes());
|
|
|
|
$this->assertSame(null, $error->getBeginColumn());
|
|
|
|
$this->assertSame(null, $error->getEndColumn());
|
|
|
|
}
|
|
|
|
}
|