Update v1.0.6
This commit is contained in:
132
vendor/nikic/php-parser/test/PhpParser/Node/NameTest.php
vendored
Normal file
132
vendor/nikic/php-parser/test/PhpParser/Node/NameTest.php
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node;
|
||||
|
||||
class NameTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstruct() {
|
||||
$name = new Name(array('foo', 'bar'));
|
||||
$this->assertSame(array('foo', 'bar'), $name->parts);
|
||||
|
||||
$name = new Name('foo\bar');
|
||||
$this->assertSame(array('foo', 'bar'), $name->parts);
|
||||
}
|
||||
|
||||
public function testGet() {
|
||||
$name = new Name('foo');
|
||||
$this->assertSame('foo', $name->getFirst());
|
||||
$this->assertSame('foo', $name->getLast());
|
||||
|
||||
$name = new Name('foo\bar');
|
||||
$this->assertSame('foo', $name->getFirst());
|
||||
$this->assertSame('bar', $name->getLast());
|
||||
}
|
||||
|
||||
public function testToString() {
|
||||
$name = new Name('foo\bar');
|
||||
|
||||
$this->assertSame('foo\bar', (string) $name);
|
||||
$this->assertSame('foo\bar', $name->toString());
|
||||
$this->assertSame('foo_bar', $name->toString('_'));
|
||||
}
|
||||
|
||||
public function testSet() {
|
||||
$name = new Name('foo');
|
||||
|
||||
$name->set('foo\bar');
|
||||
$this->assertSame('foo\bar', $name->toString());
|
||||
|
||||
$name->set(array('foo', 'bar'));
|
||||
$this->assertSame('foo\bar', $name->toString());
|
||||
|
||||
$name->set(new Name('foo\bar'));
|
||||
$this->assertSame('foo\bar', $name->toString());
|
||||
}
|
||||
|
||||
public function testSetFirst() {
|
||||
$name = new Name('foo');
|
||||
|
||||
$name->setFirst('bar');
|
||||
$this->assertSame('bar', $name->toString());
|
||||
|
||||
$name->setFirst('A\B');
|
||||
$this->assertSame('A\B', $name->toString());
|
||||
|
||||
$name->setFirst('C');
|
||||
$this->assertSame('C\B', $name->toString());
|
||||
|
||||
$name->setFirst('D\E');
|
||||
$this->assertSame('D\E\B', $name->toString());
|
||||
}
|
||||
|
||||
public function testSetLast() {
|
||||
$name = new Name('foo');
|
||||
|
||||
$name->setLast('bar');
|
||||
$this->assertSame('bar', $name->toString());
|
||||
|
||||
$name->setLast('A\B');
|
||||
$this->assertSame('A\B', $name->toString());
|
||||
|
||||
$name->setLast('C');
|
||||
$this->assertSame('A\C', $name->toString());
|
||||
|
||||
$name->setLast('D\E');
|
||||
$this->assertSame('A\D\E', $name->toString());
|
||||
}
|
||||
|
||||
public function testAppend() {
|
||||
$name = new Name('foo');
|
||||
|
||||
$name->append('bar');
|
||||
$this->assertSame('foo\bar', $name->toString());
|
||||
|
||||
$name->append('bar\foo');
|
||||
$this->assertSame('foo\bar\bar\foo', $name->toString());
|
||||
}
|
||||
|
||||
public function testPrepend() {
|
||||
$name = new Name('foo');
|
||||
|
||||
$name->prepend('bar');
|
||||
$this->assertSame('bar\foo', $name->toString());
|
||||
|
||||
$name->prepend('foo\bar');
|
||||
$this->assertSame('foo\bar\bar\foo', $name->toString());
|
||||
}
|
||||
|
||||
public function testIs() {
|
||||
$name = new Name('foo');
|
||||
$this->assertTrue ($name->isUnqualified());
|
||||
$this->assertFalse($name->isQualified());
|
||||
$this->assertFalse($name->isFullyQualified());
|
||||
$this->assertFalse($name->isRelative());
|
||||
|
||||
$name = new Name('foo\bar');
|
||||
$this->assertFalse($name->isUnqualified());
|
||||
$this->assertTrue ($name->isQualified());
|
||||
$this->assertFalse($name->isFullyQualified());
|
||||
$this->assertFalse($name->isRelative());
|
||||
|
||||
$name = new Name\FullyQualified('foo');
|
||||
$this->assertFalse($name->isUnqualified());
|
||||
$this->assertFalse($name->isQualified());
|
||||
$this->assertTrue ($name->isFullyQualified());
|
||||
$this->assertFalse($name->isRelative());
|
||||
|
||||
$name = new Name\Relative('foo');
|
||||
$this->assertFalse($name->isUnqualified());
|
||||
$this->assertFalse($name->isQualified());
|
||||
$this->assertFalse($name->isFullyQualified());
|
||||
$this->assertTrue ($name->isRelative());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage When changing a name you need to pass either a string, an array or a Name node
|
||||
*/
|
||||
public function testInvalidArg() {
|
||||
$name = new Name('foo');
|
||||
$name->set(new \stdClass);
|
||||
}
|
||||
}
|
25
vendor/nikic/php-parser/test/PhpParser/Node/Scalar/MagicConstTest.php
vendored
Normal file
25
vendor/nikic/php-parser/test/PhpParser/Node/Scalar/MagicConstTest.php
vendored
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__'),
|
||||
);
|
||||
}
|
||||
}
|
61
vendor/nikic/php-parser/test/PhpParser/Node/Scalar/StringTest.php
vendored
Normal file
61
vendor/nikic/php-parser/test/PhpParser/Node/Scalar/StringTest.php
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node\Scalar;
|
||||
|
||||
class StringTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideTestParseEscapeSequences
|
||||
*/
|
||||
public function testParseEscapeSequences($expected, $string, $quote) {
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
String_::parseEscapeSequences($string, $quote)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTestParse
|
||||
*/
|
||||
public function testCreate($expected, $string) {
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
String_::parse($string)
|
||||
);
|
||||
}
|
||||
|
||||
public function provideTestParseEscapeSequences() {
|
||||
return array(
|
||||
array('"', '\\"', '"'),
|
||||
array('\\"', '\\"', '`'),
|
||||
array('\\"\\`', '\\"\\`', null),
|
||||
array("\\\$\n\r\t\f\v", '\\\\\$\n\r\t\f\v', null),
|
||||
array("\x1B", '\e', null),
|
||||
array(chr(255), '\xFF', null),
|
||||
array(chr(255), '\377', null),
|
||||
array(chr(0), '\400', null),
|
||||
array("\0", '\0', null),
|
||||
array('\xFF', '\\\\xFF', null),
|
||||
);
|
||||
}
|
||||
|
||||
public function provideTestParse() {
|
||||
$tests = array(
|
||||
array('A', '\'A\''),
|
||||
array('A', 'b\'A\''),
|
||||
array('A', '"A"'),
|
||||
array('A', 'b"A"'),
|
||||
array('\\', '\'\\\\\''),
|
||||
array('\'', '\'\\\'\''),
|
||||
);
|
||||
|
||||
foreach ($this->provideTestParseEscapeSequences() as $i => $test) {
|
||||
// skip second and third tests, they aren't for double quotes
|
||||
if ($i != 1 && $i != 2) {
|
||||
$tests[] = array($test[0], '"' . $test[1] . '"');
|
||||
}
|
||||
}
|
||||
|
||||
return $tests;
|
||||
}
|
||||
}
|
63
vendor/nikic/php-parser/test/PhpParser/Node/Stmt/ClassMethodTest.php
vendored
Normal file
63
vendor/nikic/php-parser/test/PhpParser/Node/Stmt/ClassMethodTest.php
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
class ClassMethodTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideModifiers
|
||||
*/
|
||||
public function testModifiers($modifier) {
|
||||
$node = new ClassMethod('foo', array(
|
||||
'type' => constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier))
|
||||
));
|
||||
|
||||
$this->assertTrue($node->{'is' . $modifier}());
|
||||
}
|
||||
|
||||
public function testNoModifiers() {
|
||||
$node = new ClassMethod('foo', array('type' => 0));
|
||||
|
||||
$this->assertTrue($node->isPublic());
|
||||
$this->assertFalse($node->isProtected());
|
||||
$this->assertFalse($node->isPrivate());
|
||||
$this->assertFalse($node->isAbstract());
|
||||
$this->assertFalse($node->isFinal());
|
||||
$this->assertFalse($node->isStatic());
|
||||
}
|
||||
|
||||
public function provideModifiers() {
|
||||
return array(
|
||||
array('public'),
|
||||
array('protected'),
|
||||
array('private'),
|
||||
array('abstract'),
|
||||
array('final'),
|
||||
array('static'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that implicit public modifier detection for method is working
|
||||
*
|
||||
* @dataProvider implicitPublicModifiers
|
||||
*
|
||||
* @param integer $modifier Node type modifier
|
||||
*/
|
||||
public function testImplicitPublic($modifier)
|
||||
{
|
||||
$node = new ClassMethod('foo', array(
|
||||
'type' => constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier))
|
||||
));
|
||||
|
||||
$this->assertTrue($node->isPublic(), 'Node should be implicitly public');
|
||||
}
|
||||
|
||||
public function implicitPublicModifiers() {
|
||||
return array(
|
||||
array('abstract'),
|
||||
array('final'),
|
||||
array('static'),
|
||||
);
|
||||
}
|
||||
}
|
59
vendor/nikic/php-parser/test/PhpParser/Node/Stmt/ClassTest.php
vendored
Normal file
59
vendor/nikic/php-parser/test/PhpParser/Node/Stmt/ClassTest.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
class ClassTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testIsAbstract() {
|
||||
$class = new Class_('Foo', array('type' => Class_::MODIFIER_ABSTRACT));
|
||||
$this->assertTrue($class->isAbstract());
|
||||
|
||||
$class = new Class_('Foo');
|
||||
$this->assertFalse($class->isAbstract());
|
||||
}
|
||||
|
||||
public function testIsFinal() {
|
||||
$class = new Class_('Foo', array('type' => Class_::MODIFIER_FINAL));
|
||||
$this->assertTrue($class->isFinal());
|
||||
|
||||
$class = new Class_('Foo');
|
||||
$this->assertFalse($class->isFinal());
|
||||
}
|
||||
|
||||
public function testGetMethods() {
|
||||
$methods = array(
|
||||
new ClassMethod('foo'),
|
||||
new ClassMethod('bar'),
|
||||
new ClassMethod('fooBar'),
|
||||
);
|
||||
$class = new Class_('Foo', array(
|
||||
'stmts' => array(
|
||||
new TraitUse(array()),
|
||||
$methods[0],
|
||||
new ClassConst(array()),
|
||||
$methods[1],
|
||||
new Property(0, array()),
|
||||
$methods[2],
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertSame($methods, $class->getMethods());
|
||||
}
|
||||
|
||||
public function testGetMethod() {
|
||||
$methodConstruct = new ClassMethod('__CONSTRUCT');
|
||||
$methodTest = new ClassMethod('test');
|
||||
$class = new Class_('Foo', array(
|
||||
'stmts' => array(
|
||||
new ClassConst(array()),
|
||||
$methodConstruct,
|
||||
new Property(0, array()),
|
||||
$methodTest,
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertSame($methodConstruct, $class->getMethod('__construct'));
|
||||
$this->assertSame($methodTest, $class->getMethod('test'));
|
||||
$this->assertNull($class->getMethod('nonExisting'));
|
||||
}
|
||||
}
|
26
vendor/nikic/php-parser/test/PhpParser/Node/Stmt/InterfaceTest.php
vendored
Normal file
26
vendor/nikic/php-parser/test/PhpParser/Node/Stmt/InterfaceTest.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
class InterfaceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetMethods() {
|
||||
$methods = array(
|
||||
new ClassMethod('foo'),
|
||||
new ClassMethod('bar'),
|
||||
);
|
||||
$interface = new Class_('Foo', array(
|
||||
'stmts' => array(
|
||||
new Node\Stmt\ClassConst(array(new Node\Const_('C1', new Node\Scalar\String_('C1')))),
|
||||
$methods[0],
|
||||
new Node\Stmt\ClassConst(array(new Node\Const_('C2', new Node\Scalar\String_('C2')))),
|
||||
$methods[1],
|
||||
new Node\Stmt\ClassConst(array(new Node\Const_('C3', new Node\Scalar\String_('C3')))),
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertSame($methods, $interface->getMethods());
|
||||
}
|
||||
}
|
44
vendor/nikic/php-parser/test/PhpParser/Node/Stmt/PropertyTest.php
vendored
Normal file
44
vendor/nikic/php-parser/test/PhpParser/Node/Stmt/PropertyTest.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
class PropertyTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideModifiers
|
||||
*/
|
||||
public function testModifiers($modifier) {
|
||||
$node = new Property(
|
||||
constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier)),
|
||||
array() // invalid
|
||||
);
|
||||
|
||||
$this->assertTrue($node->{'is' . $modifier}());
|
||||
}
|
||||
|
||||
public function testNoModifiers() {
|
||||
$node = new Property(0, array());
|
||||
|
||||
$this->assertTrue($node->isPublic());
|
||||
$this->assertFalse($node->isProtected());
|
||||
$this->assertFalse($node->isPrivate());
|
||||
$this->assertFalse($node->isStatic());
|
||||
}
|
||||
|
||||
public function testStaticImplicitlyPublic() {
|
||||
$node = new Property(Class_::MODIFIER_STATIC, array());
|
||||
$this->assertTrue($node->isPublic());
|
||||
$this->assertFalse($node->isProtected());
|
||||
$this->assertFalse($node->isPrivate());
|
||||
$this->assertTrue($node->isStatic());
|
||||
}
|
||||
|
||||
public function provideModifiers() {
|
||||
return array(
|
||||
array('public'),
|
||||
array('protected'),
|
||||
array('private'),
|
||||
array('static'),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user