Enforce Name|string for names in builders

While array (with name components) could technically be allowed (as
they are supported by the Name node itself), more likely than not
an array would due to incorrect usage of the API (e.g. array instead
of variadics).
This commit is contained in:
Nikita Popov 2014-12-19 18:50:16 +01:00
parent ba625063e7
commit 7ab88416ac
2 changed files with 12 additions and 3 deletions

View File

@ -48,9 +48,9 @@ abstract class BuilderAbstract implements Builder {
} else {
return new Name($name);
}
} else {
return new Name($name);
}
throw new \LogicException('Name must be a string or an instance of PhpParser\Node\Name');
}
/**

View File

@ -145,8 +145,17 @@ DOC;
* @expectedException \LogicException
* @expectedExceptionMessage Name cannot be empty
*/
public function testInvalidName() {
public function testEmptyName() {
$this->createClassBuilder('Test')
->extend('');
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage Name must be a string or an instance of PhpParser\Node\Name
*/
public function testInvalidName() {
$this->createClassBuilder('Test')
->extend(['Foo']);
}
}