mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-30 04:29:15 +01:00
Add some tests for new use builders
This commit is contained in:
parent
53c732a96d
commit
b855c1ca23
@ -1,7 +1,11 @@
|
||||
Version 4.0.4-dev
|
||||
-----------------
|
||||
|
||||
Nothing yet.
|
||||
### Added
|
||||
|
||||
* The following methods have been added to `BuilderFactory`:
|
||||
* `useFunction()`
|
||||
* `useConst()`
|
||||
|
||||
Version 4.0.3 (2018-07-15)
|
||||
--------------------------
|
||||
|
@ -106,7 +106,7 @@ class BuilderFactory
|
||||
*
|
||||
* @param Node\Name|string $name Name of the entity (namespace or class) to alias
|
||||
*
|
||||
* @return Builder\Use_ The create use builder
|
||||
* @return Builder\Use_ The created use builder
|
||||
*/
|
||||
public function use($name) : Builder\Use_ {
|
||||
return new Builder\Use_($name, Use_::TYPE_NORMAL);
|
||||
@ -117,7 +117,7 @@ class BuilderFactory
|
||||
*
|
||||
* @param Node\Name|string $name Name of the function to alias
|
||||
*
|
||||
* @return Builder\Use_ The create use builder
|
||||
* @return Builder\Use_ The created use function builder
|
||||
*/
|
||||
public function useFunction($name) : Builder\Use_ {
|
||||
return new Builder\Use_($name, Use_::TYPE_FUNCTION);
|
||||
@ -128,7 +128,7 @@ class BuilderFactory
|
||||
*
|
||||
* @param Node\Name|string $name Name of the const to alias
|
||||
*
|
||||
* @return Builder\Use_ The create use builder
|
||||
* @return Builder\Use_ The created use const builder
|
||||
*/
|
||||
public function useConst($name) : Builder\Use_ {
|
||||
return new Builder\Use_($name, Use_::TYPE_CONSTANT);
|
||||
|
@ -26,5 +26,10 @@ class UseTest extends TestCase
|
||||
$this->assertEquals(new Stmt\Use_([
|
||||
new Stmt\UseUse(new Name('foo\bar'), 'foo')
|
||||
], Stmt\Use_::TYPE_FUNCTION), $node);
|
||||
|
||||
$node = $this->createUseBuilder('foo\BAR', Stmt\Use_::TYPE_CONSTANT)->as('FOO')->getNode();
|
||||
$this->assertEquals(new Stmt\Use_([
|
||||
new Stmt\UseUse(new Name('foo\BAR'), 'FOO')
|
||||
], Stmt\Use_::TYPE_CONSTANT), $node);
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ class BuilderFactoryTest extends TestCase
|
||||
['property', Builder\Property::class],
|
||||
['param', Builder\Param::class],
|
||||
['use', Builder\Use_::class],
|
||||
['useFunction', Builder\Use_::class],
|
||||
['useConst', Builder\Use_::class],
|
||||
];
|
||||
}
|
||||
|
||||
@ -217,6 +219,8 @@ class BuilderFactoryTest extends TestCase
|
||||
$node = $factory->namespace('Name\Space')
|
||||
->addStmt($factory->use('Foo\Bar\SomeOtherClass'))
|
||||
->addStmt($factory->use('Foo\Bar')->as('A'))
|
||||
->addStmt($factory->useFunction('strlen'))
|
||||
->addStmt($factory->useConst('PHP_VERSION'))
|
||||
->addStmt($factory
|
||||
->class('SomeClass')
|
||||
->extend('SomeOtherClass')
|
||||
@ -254,6 +258,8 @@ namespace Name\Space;
|
||||
|
||||
use Foo\Bar\SomeOtherClass;
|
||||
use Foo\Bar as A;
|
||||
use function strlen;
|
||||
use const PHP_VERSION;
|
||||
abstract class SomeClass extends SomeOtherClass implements A\Few, \Interfaces
|
||||
{
|
||||
protected $someProperty;
|
||||
|
Loading…
Reference in New Issue
Block a user