Laravel version update
Laravel version update
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace PhpParser\Node;
|
||||
|
||||
class NameTest extends \PHPUnit_Framework_TestCase
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class NameTest extends TestCase
|
||||
{
|
||||
public function testConstruct() {
|
||||
$name = new Name(array('foo', 'bar'));
|
||||
$this->assertSame(array('foo', 'bar'), $name->parts);
|
||||
$name = new Name(['foo', 'bar']);
|
||||
$this->assertSame(['foo', 'bar'], $name->parts);
|
||||
|
||||
$name = new Name('foo\bar');
|
||||
$this->assertSame(array('foo', 'bar'), $name->parts);
|
||||
$this->assertSame(['foo', 'bar'], $name->parts);
|
||||
|
||||
$name = new Name($name);
|
||||
$this->assertSame(['foo', 'bar'], $name->parts);
|
||||
}
|
||||
|
||||
public function testGet() {
|
||||
@@ -23,93 +28,61 @@ class NameTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
public function testToString() {
|
||||
$name = new Name('foo\bar');
|
||||
$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());
|
||||
$this->assertSame('Foo\Bar', (string) $name);
|
||||
$this->assertSame('Foo\Bar', $name->toString());
|
||||
$this->assertSame('foo\bar', $name->toLowerString());
|
||||
}
|
||||
|
||||
public function testSlice() {
|
||||
$name = new Name('foo\bar');
|
||||
$this->assertEquals(new Name('foo\bar'), $name->slice(0));
|
||||
$this->assertEquals(new Name('bar'), $name->slice(1));
|
||||
$this->assertEquals(new Name([]), $name->slice(2));
|
||||
$name = new Name('foo\bar\baz');
|
||||
$this->assertEquals(new Name('foo\bar\baz'), $name->slice(0));
|
||||
$this->assertEquals(new Name('bar\baz'), $name->slice(1));
|
||||
$this->assertNull($name->slice(3));
|
||||
$this->assertEquals(new Name('foo\bar\baz'), $name->slice(-3));
|
||||
$this->assertEquals(new Name('bar\baz'), $name->slice(-2));
|
||||
$this->assertEquals(new Name('foo\bar'), $name->slice(0, -1));
|
||||
$this->assertNull($name->slice(0, -3));
|
||||
$this->assertEquals(new Name('bar'), $name->slice(1, -1));
|
||||
$this->assertNull($name->slice(1, -2));
|
||||
$this->assertEquals(new Name('bar'), $name->slice(-2, 1));
|
||||
$this->assertEquals(new Name('bar'), $name->slice(-2, -1));
|
||||
$this->assertNull($name->slice(-2, -2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OutOfBoundsException
|
||||
* @expectedExceptionMessage Offset 4 is out of bounds
|
||||
*/
|
||||
public function testSliceException() {
|
||||
public function testSliceOffsetTooLarge() {
|
||||
(new Name('foo\bar\baz'))->slice(4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OutOfBoundsException
|
||||
* @expectedExceptionMessage Offset -4 is out of bounds
|
||||
*/
|
||||
public function testSliceOffsetTooSmall() {
|
||||
(new Name('foo\bar\baz'))->slice(-4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OutOfBoundsException
|
||||
* @expectedExceptionMessage Length 4 is out of bounds
|
||||
*/
|
||||
public function testSliceLengthTooLarge() {
|
||||
(new Name('foo\bar\baz'))->slice(0, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OutOfBoundsException
|
||||
* @expectedExceptionMessage Length -4 is out of bounds
|
||||
*/
|
||||
public function testSliceLengthTooSmall() {
|
||||
(new Name('foo\bar\baz'))->slice(0, -4);
|
||||
}
|
||||
|
||||
public function testConcat() {
|
||||
$this->assertEquals(new Name('foo\bar\baz'), Name::concat('foo', 'bar\baz'));
|
||||
$this->assertEquals(
|
||||
@@ -123,42 +96,78 @@ class NameTest extends \PHPUnit_Framework_TestCase
|
||||
Name\Relative::concat(new Name\FullyQualified('foo\bar'), 'baz', $attributes)
|
||||
);
|
||||
|
||||
$this->assertEquals(new Name('foo'), Name::concat([], 'foo'));
|
||||
$this->assertEquals(new Name([]), Name::concat([], []));
|
||||
$this->assertEquals(new Name('foo'), Name::concat(null, 'foo'));
|
||||
$this->assertEquals(new Name('foo'), Name::concat('foo', null));
|
||||
$this->assertNull(Name::concat(null, null));
|
||||
}
|
||||
|
||||
public function testIs() {
|
||||
public function testNameTypes() {
|
||||
$name = new Name('foo');
|
||||
$this->assertTrue ($name->isUnqualified());
|
||||
$this->assertTrue($name->isUnqualified());
|
||||
$this->assertFalse($name->isQualified());
|
||||
$this->assertFalse($name->isFullyQualified());
|
||||
$this->assertFalse($name->isRelative());
|
||||
$this->assertSame('foo', $name->toCodeString());
|
||||
|
||||
$name = new Name('foo\bar');
|
||||
$this->assertFalse($name->isUnqualified());
|
||||
$this->assertTrue ($name->isQualified());
|
||||
$this->assertTrue($name->isQualified());
|
||||
$this->assertFalse($name->isFullyQualified());
|
||||
$this->assertFalse($name->isRelative());
|
||||
$this->assertSame('foo\bar', $name->toCodeString());
|
||||
|
||||
$name = new Name\FullyQualified('foo');
|
||||
$this->assertFalse($name->isUnqualified());
|
||||
$this->assertFalse($name->isQualified());
|
||||
$this->assertTrue ($name->isFullyQualified());
|
||||
$this->assertTrue($name->isFullyQualified());
|
||||
$this->assertFalse($name->isRelative());
|
||||
$this->assertSame('\foo', $name->toCodeString());
|
||||
|
||||
$name = new Name\Relative('foo');
|
||||
$this->assertFalse($name->isUnqualified());
|
||||
$this->assertFalse($name->isQualified());
|
||||
$this->assertFalse($name->isFullyQualified());
|
||||
$this->assertTrue ($name->isRelative());
|
||||
$this->assertTrue($name->isRelative());
|
||||
$this->assertSame('namespace\foo', $name->toCodeString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage When changing a name you need to pass either a string, an array or a Name node
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Expected string, array of parts or Name instance
|
||||
*/
|
||||
public function testInvalidArg() {
|
||||
$name = new Name('foo');
|
||||
$name->set(new \stdClass);
|
||||
Name::concat('foo', new \stdClass);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Name cannot be empty
|
||||
*/
|
||||
public function testInvalidEmptyString() {
|
||||
new Name('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Name cannot be empty
|
||||
*/
|
||||
public function testInvalidEmptyArray() {
|
||||
new Name([]);
|
||||
}
|
||||
|
||||
/** @dataProvider provideTestIsSpecialClassName */
|
||||
public function testIsSpecialClassName($name, $expected) {
|
||||
$name = new Name($name);
|
||||
$this->assertSame($expected, $name->isSpecialClassName());
|
||||
}
|
||||
|
||||
public function provideTestIsSpecialClassName() {
|
||||
return [
|
||||
['self', true],
|
||||
['PARENT', true],
|
||||
['Static', true],
|
||||
['self\not', false],
|
||||
['not\self', false],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user