mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-17 07:08:14 +01:00
Add Scalar\MagicConst->getName()
Return magic constant name, e.g. __CLASS__. Resolves #95.
This commit is contained in:
parent
1c8481bff6
commit
70077039b4
@ -14,4 +14,11 @@ abstract class MagicConst extends Scalar
|
||||
public function __construct(array $attributes = array()) {
|
||||
parent::__construct(array(), $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of magic constant.
|
||||
*
|
||||
* @return string Name of magic constant
|
||||
*/
|
||||
abstract public function getName();
|
||||
}
|
@ -6,4 +6,7 @@ use PhpParser\Node\Scalar\MagicConst;
|
||||
|
||||
class Class_ extends MagicConst
|
||||
{
|
||||
public function getName() {
|
||||
return '__CLASS__';
|
||||
}
|
||||
}
|
@ -6,4 +6,7 @@ use PhpParser\Node\Scalar\MagicConst;
|
||||
|
||||
class Dir extends MagicConst
|
||||
{
|
||||
public function getName() {
|
||||
return '__DIR__';
|
||||
}
|
||||
}
|
@ -6,4 +6,7 @@ use PhpParser\Node\Scalar\MagicConst;
|
||||
|
||||
class File extends MagicConst
|
||||
{
|
||||
public function getName() {
|
||||
return '__FILE__';
|
||||
}
|
||||
}
|
@ -6,4 +6,7 @@ use PhpParser\Node\Scalar\MagicConst;
|
||||
|
||||
class Function_ extends MagicConst
|
||||
{
|
||||
public function getName() {
|
||||
return '__FUNCTION__';
|
||||
}
|
||||
}
|
@ -6,4 +6,7 @@ use PhpParser\Node\Scalar\MagicConst;
|
||||
|
||||
class Line extends MagicConst
|
||||
{
|
||||
public function getName() {
|
||||
return '__LINE__';
|
||||
}
|
||||
}
|
@ -6,4 +6,7 @@ use PhpParser\Node\Scalar\MagicConst;
|
||||
|
||||
class Method extends MagicConst
|
||||
{
|
||||
public function getName() {
|
||||
return '__METHOD__';
|
||||
}
|
||||
}
|
@ -6,4 +6,7 @@ use PhpParser\Node\Scalar\MagicConst;
|
||||
|
||||
class Namespace_ extends MagicConst
|
||||
{
|
||||
public function getName() {
|
||||
return '__NAMESPACE__';
|
||||
}
|
||||
}
|
@ -6,4 +6,7 @@ use PhpParser\Node\Scalar\MagicConst;
|
||||
|
||||
class Trait_ extends MagicConst
|
||||
{
|
||||
public function getName() {
|
||||
return '__TRAIT__';
|
||||
}
|
||||
}
|
25
test/PhpParser/Node/Scalar/MagicConstTest.php
Normal file
25
test/PhpParser/Node/Scalar/MagicConstTest.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node\Scalar;
|
||||
|
||||
class MagicConstTest extends \PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* @dataProvider provideTestGetName
|
||||
*/
|
||||
public function testGetName(MagicConst $magicConst, $name) {
|
||||
$this->assertSame($name, $magicConst->getName());
|
||||
}
|
||||
|
||||
public function provideTestGetName() {
|
||||
return array(
|
||||
array(new MagicConst\Class_, '__CLASS__'),
|
||||
array(new MagicConst\Dir, '__DIR__'),
|
||||
array(new MagicConst\File, '__FILE__'),
|
||||
array(new MagicConst\Function_, '__FUNCTION__'),
|
||||
array(new MagicConst\Line, '__LINE__'),
|
||||
array(new MagicConst\Method, '__METHOD__'),
|
||||
array(new MagicConst\Namespace_, '__NAMESPACE__'),
|
||||
array(new MagicConst\Trait_, '__TRAIT__'),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user