Add some tests for new use builders

This commit is contained in:
Nikita Popov 2018-07-20 21:43:43 +02:00
parent 53c732a96d
commit b855c1ca23
4 changed files with 28 additions and 13 deletions

View File

@ -1,7 +1,11 @@
Version 4.0.4-dev 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) Version 4.0.3 (2018-07-15)
-------------------------- --------------------------

View File

@ -106,7 +106,7 @@ class BuilderFactory
* *
* @param Node\Name|string $name Name of the entity (namespace or class) to alias * @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_ { public function use($name) : Builder\Use_ {
return new Builder\Use_($name, Use_::TYPE_NORMAL); 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 * @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_ { public function useFunction($name) : Builder\Use_ {
return new Builder\Use_($name, Use_::TYPE_FUNCTION); 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 * @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_ { public function useConst($name) : Builder\Use_ {
return new Builder\Use_($name, Use_::TYPE_CONSTANT); return new Builder\Use_($name, Use_::TYPE_CONSTANT);

View File

@ -26,5 +26,10 @@ class UseTest extends TestCase
$this->assertEquals(new Stmt\Use_([ $this->assertEquals(new Stmt\Use_([
new Stmt\UseUse(new Name('foo\bar'), 'foo') new Stmt\UseUse(new Name('foo\bar'), 'foo')
], Stmt\Use_::TYPE_FUNCTION), $node); ], 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);
} }
} }

View File

@ -25,15 +25,17 @@ class BuilderFactoryTest extends TestCase
public function provideTestFactory() { public function provideTestFactory() {
return [ return [
['namespace', Builder\Namespace_::class], ['namespace', Builder\Namespace_::class],
['class', Builder\Class_::class], ['class', Builder\Class_::class],
['interface', Builder\Interface_::class], ['interface', Builder\Interface_::class],
['trait', Builder\Trait_::class], ['trait', Builder\Trait_::class],
['method', Builder\Method::class], ['method', Builder\Method::class],
['function', Builder\Function_::class], ['function', Builder\Function_::class],
['property', Builder\Property::class], ['property', Builder\Property::class],
['param', Builder\Param::class], ['param', Builder\Param::class],
['use', Builder\Use_::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') $node = $factory->namespace('Name\Space')
->addStmt($factory->use('Foo\Bar\SomeOtherClass')) ->addStmt($factory->use('Foo\Bar\SomeOtherClass'))
->addStmt($factory->use('Foo\Bar')->as('A')) ->addStmt($factory->use('Foo\Bar')->as('A'))
->addStmt($factory->useFunction('strlen'))
->addStmt($factory->useConst('PHP_VERSION'))
->addStmt($factory ->addStmt($factory
->class('SomeClass') ->class('SomeClass')
->extend('SomeOtherClass') ->extend('SomeOtherClass')
@ -254,6 +258,8 @@ namespace Name\Space;
use Foo\Bar\SomeOtherClass; use Foo\Bar\SomeOtherClass;
use Foo\Bar as A; use Foo\Bar as A;
use function strlen;
use const PHP_VERSION;
abstract class SomeClass extends SomeOtherClass implements A\Few, \Interfaces abstract class SomeClass extends SomeOtherClass implements A\Few, \Interfaces
{ {
protected $someProperty; protected $someProperty;