the whole shebang
This commit is contained in:
130
vendor/nikic/php-parser/test/PHPParser/Tests/Node/NameTest.php
vendored
Normal file
130
vendor/nikic/php-parser/test/PHPParser/Tests/Node/NameTest.php
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
class PHPParser_Tests_Node_NameTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstruct() {
|
||||
$name = new PHPParser_Node_Name(array('foo', 'bar'));
|
||||
$this->assertEquals(array('foo', 'bar'), $name->parts);
|
||||
|
||||
$name = new PHPParser_Node_Name('foo\bar');
|
||||
$this->assertEquals(array('foo', 'bar'), $name->parts);
|
||||
}
|
||||
|
||||
public function testGet() {
|
||||
$name = new PHPParser_Node_Name('foo');
|
||||
$this->assertEquals('foo', $name->getFirst());
|
||||
$this->assertEquals('foo', $name->getLast());
|
||||
|
||||
$name = new PHPParser_Node_Name('foo\bar');
|
||||
$this->assertEquals('foo', $name->getFirst());
|
||||
$this->assertEquals('bar', $name->getLast());
|
||||
}
|
||||
|
||||
public function testToString() {
|
||||
$name = new PHPParser_Node_Name('foo\bar');
|
||||
|
||||
$this->assertEquals('foo\bar', (string) $name);
|
||||
$this->assertEquals('foo\bar', $name->toString());
|
||||
$this->assertEquals('foo_bar', $name->toString('_'));
|
||||
}
|
||||
|
||||
public function testSet() {
|
||||
$name = new PHPParser_Node_Name('foo');
|
||||
|
||||
$name->set('foo\bar');
|
||||
$this->assertEquals('foo\bar', $name->toString());
|
||||
|
||||
$name->set(array('foo', 'bar'));
|
||||
$this->assertEquals('foo\bar', $name->toString());
|
||||
|
||||
$name->set(new PHPParser_Node_Name('foo\bar'));
|
||||
$this->assertEquals('foo\bar', $name->toString());
|
||||
}
|
||||
|
||||
public function testSetFirst() {
|
||||
$name = new PHPParser_Node_Name('foo');
|
||||
|
||||
$name->setFirst('bar');
|
||||
$this->assertEquals('bar', $name->toString());
|
||||
|
||||
$name->setFirst('A\B');
|
||||
$this->assertEquals('A\B', $name->toString());
|
||||
|
||||
$name->setFirst('C');
|
||||
$this->assertEquals('C\B', $name->toString());
|
||||
|
||||
$name->setFirst('D\E');
|
||||
$this->assertEquals('D\E\B', $name->toString());
|
||||
}
|
||||
|
||||
public function testSetLast() {
|
||||
$name = new PHPParser_Node_Name('foo');
|
||||
|
||||
$name->setLast('bar');
|
||||
$this->assertEquals('bar', $name->toString());
|
||||
|
||||
$name->setLast('A\B');
|
||||
$this->assertEquals('A\B', $name->toString());
|
||||
|
||||
$name->setLast('C');
|
||||
$this->assertEquals('A\C', $name->toString());
|
||||
|
||||
$name->setLast('D\E');
|
||||
$this->assertEquals('A\D\E', $name->toString());
|
||||
}
|
||||
|
||||
public function testAppend() {
|
||||
$name = new PHPParser_Node_Name('foo');
|
||||
|
||||
$name->append('bar');
|
||||
$this->assertEquals('foo\bar', $name->toString());
|
||||
|
||||
$name->append('bar\foo');
|
||||
$this->assertEquals('foo\bar\bar\foo', $name->toString());
|
||||
}
|
||||
|
||||
public function testPrepend() {
|
||||
$name = new PHPParser_Node_Name('foo');
|
||||
|
||||
$name->prepend('bar');
|
||||
$this->assertEquals('bar\foo', $name->toString());
|
||||
|
||||
$name->prepend('foo\bar');
|
||||
$this->assertEquals('foo\bar\bar\foo', $name->toString());
|
||||
}
|
||||
|
||||
public function testIs() {
|
||||
$name = new PHPParser_Node_Name('foo');
|
||||
$this->assertTrue ($name->isUnqualified());
|
||||
$this->assertFalse($name->isQualified());
|
||||
$this->assertFalse($name->isFullyQualified());
|
||||
$this->assertFalse($name->isRelative());
|
||||
|
||||
$name = new PHPParser_Node_Name('foo\bar');
|
||||
$this->assertFalse($name->isUnqualified());
|
||||
$this->assertTrue ($name->isQualified());
|
||||
$this->assertFalse($name->isFullyQualified());
|
||||
$this->assertFalse($name->isRelative());
|
||||
|
||||
$name = new PHPParser_Node_Name_FullyQualified('foo');
|
||||
$this->assertFalse($name->isUnqualified());
|
||||
$this->assertFalse($name->isQualified());
|
||||
$this->assertTrue ($name->isFullyQualified());
|
||||
$this->assertFalse($name->isRelative());
|
||||
|
||||
$name = new PHPParser_Node_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 PHPParser_Node_Name('foo');
|
||||
$name->set(new stdClass);
|
||||
}
|
||||
}
|
59
vendor/nikic/php-parser/test/PHPParser/Tests/Node/Scalar/StringTest.php
vendored
Normal file
59
vendor/nikic/php-parser/test/PHPParser/Tests/Node/Scalar/StringTest.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
class PHPParser_Tests_Node_Scalar_StringTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideTestParseEscapeSequences
|
||||
*/
|
||||
public function testParseEscapeSequences($expected, $string, $quote) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
PHPParser_Node_Scalar_String::parseEscapeSequences($string, $quote)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTestParse
|
||||
*/
|
||||
public function testCreate($expected, $string) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
PHPParser_Node_Scalar_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;
|
||||
}
|
||||
}
|
35
vendor/nikic/php-parser/test/PHPParser/Tests/Node/Stmt/ClassMethodTest.php
vendored
Normal file
35
vendor/nikic/php-parser/test/PHPParser/Tests/Node/Stmt/ClassMethodTest.php
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
class PHPParser_Tests_Node_Stmt_ClassMethodTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideModifiers
|
||||
*/
|
||||
public function testModifiers($modifier) {
|
||||
$node = new PHPParser_Node_Stmt_ClassMethod('foo', array(
|
||||
'type' => constant('PHPParser_Node_Stmt_Class::MODIFIER_' . strtoupper($modifier))
|
||||
));
|
||||
|
||||
$this->assertTrue($node->{'is' . $modifier}());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideModifiers
|
||||
*/
|
||||
public function testNoModifiers($modifier) {
|
||||
$node = new PHPParser_Node_Stmt_ClassMethod('foo', array('type' => 0));
|
||||
|
||||
$this->assertFalse($node->{'is' . $modifier}());
|
||||
}
|
||||
|
||||
public function provideModifiers() {
|
||||
return array(
|
||||
array('public'),
|
||||
array('protected'),
|
||||
array('private'),
|
||||
array('abstract'),
|
||||
array('final'),
|
||||
array('static'),
|
||||
);
|
||||
}
|
||||
}
|
40
vendor/nikic/php-parser/test/PHPParser/Tests/Node/Stmt/ClassTest.php
vendored
Normal file
40
vendor/nikic/php-parser/test/PHPParser/Tests/Node/Stmt/ClassTest.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
class PHPParser_Tests_Node_Stmt_ClassTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testIsAbstract() {
|
||||
$class = new PHPParser_Node_Stmt_Class('Foo', array('type' => PHPParser_Node_Stmt_Class::MODIFIER_ABSTRACT));
|
||||
$this->assertTrue($class->isAbstract());
|
||||
|
||||
$class = new PHPParser_Node_Stmt_Class('Foo');
|
||||
$this->assertFalse($class->isAbstract());
|
||||
}
|
||||
|
||||
public function testIsFinal() {
|
||||
$class = new PHPParser_Node_Stmt_Class('Foo', array('type' => PHPParser_Node_Stmt_Class::MODIFIER_FINAL));
|
||||
$this->assertTrue($class->isFinal());
|
||||
|
||||
$class = new PHPParser_Node_Stmt_Class('Foo');
|
||||
$this->assertFalse($class->isFinal());
|
||||
}
|
||||
|
||||
public function testGetMethods() {
|
||||
$methods = array(
|
||||
new PHPParser_Node_Stmt_ClassMethod('foo'),
|
||||
new PHPParser_Node_Stmt_ClassMethod('bar'),
|
||||
new PHPParser_Node_Stmt_ClassMethod('fooBar'),
|
||||
);
|
||||
$class = new PHPParser_Node_Stmt_Class('Foo', array(
|
||||
'stmts' => array(
|
||||
new PHPParser_Node_Stmt_TraitUse(array()),
|
||||
$methods[0],
|
||||
new PHPParser_Node_Stmt_Const(array()),
|
||||
$methods[1],
|
||||
new PHPParser_Node_Stmt_Property(0, array()),
|
||||
$methods[2],
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertEquals($methods, $class->getMethods());
|
||||
}
|
||||
}
|
34
vendor/nikic/php-parser/test/PHPParser/Tests/Node/Stmt/PropertyTest.php
vendored
Normal file
34
vendor/nikic/php-parser/test/PHPParser/Tests/Node/Stmt/PropertyTest.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class PHPParser_Tests_Node_Stmt_PropertyTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideModifiers
|
||||
*/
|
||||
public function testModifiers($modifier) {
|
||||
$node = new PHPParser_Node_Stmt_Property(
|
||||
constant('PHPParser_Node_Stmt_Class::MODIFIER_' . strtoupper($modifier)),
|
||||
array() // invalid
|
||||
);
|
||||
|
||||
$this->assertTrue($node->{'is' . $modifier}());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideModifiers
|
||||
*/
|
||||
public function testNoModifiers($modifier) {
|
||||
$node = new PHPParser_Node_Stmt_Property(0, array());
|
||||
|
||||
$this->assertFalse($node->{'is' . $modifier}());
|
||||
}
|
||||
|
||||
public function provideModifiers() {
|
||||
return array(
|
||||
array('public'),
|
||||
array('protected'),
|
||||
array('private'),
|
||||
array('static'),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user