mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-26 20:04:48 +01:00
Add Identifier::toString()
For symmetry with the Name API. Also add some missing unit tests.
This commit is contained in:
parent
eaee6687e0
commit
65de924493
@ -33,6 +33,15 @@ class Identifier extends NodeAbstract
|
||||
return ['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get identifier as string.
|
||||
*
|
||||
* @return string Identifier as string.
|
||||
*/
|
||||
public function toString() : string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lowercased identifier as string.
|
||||
*
|
||||
|
30
lib/PhpParser/Node/IdentifierTest.php
Normal file
30
lib/PhpParser/Node/IdentifierTest.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class IdentifierTest extends TestCase {
|
||||
public function testToString() {
|
||||
$identifier = new Identifier('Foo');
|
||||
|
||||
$this->assertSame('Foo', (string) $identifier);
|
||||
$this->assertSame('Foo', $identifier->toString());
|
||||
$this->assertSame('foo', $identifier->toLowerString());
|
||||
}
|
||||
|
||||
/** @dataProvider provideTestIsSpecialClassName */
|
||||
public function testIsSpecialClassName($identifier, $expected) {
|
||||
$identifier = new Identifier($identifier);
|
||||
$this->assertSame($expected, $identifier->isSpecialClassName());
|
||||
}
|
||||
|
||||
public function provideTestIsSpecialClassName() {
|
||||
return [
|
||||
['self', true],
|
||||
['PARENT', true],
|
||||
['Static', true],
|
||||
['other', false],
|
||||
];
|
||||
}
|
||||
}
|
@ -28,10 +28,11 @@ class NameTest extends TestCase
|
||||
}
|
||||
|
||||
public function testToString() {
|
||||
$name = new Name('foo\bar');
|
||||
$name = new Name('Foo\Bar');
|
||||
|
||||
$this->assertSame('foo\bar', (string) $name);
|
||||
$this->assertSame('foo\bar', $name->toString());
|
||||
$this->assertSame('Foo\Bar', (string) $name);
|
||||
$this->assertSame('Foo\Bar', $name->toString());
|
||||
$this->assertSame('foo\bar', $name->toLowerString());
|
||||
}
|
||||
|
||||
public function testSlice() {
|
||||
@ -137,4 +138,20 @@ class NameTest extends TestCase
|
||||
public function testInvalidArg() {
|
||||
Name::concat('foo', new \stdClass);
|
||||
}
|
||||
|
||||
/** @dataProvider provideTestIsSpecialClassName */
|
||||
public function testIsSpecialClassName($name, $expected) {
|
||||
$name = new Name($name);
|
||||
$this->assertSame($expected, $name->isSpecialClassName());
|
||||
}
|
||||
|
||||
public function provideTestIsSpecialClassName() {
|
||||
return [
|
||||
['self', true],
|
||||
['PARENT', true],
|
||||
['Static', true],
|
||||
['self\not', false],
|
||||
['not\self', false],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user