X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fnikic%2Fphp-parser%2Ftest%2FPhpParser%2FNode%2FStmt%2FClassMethodTest.php;fp=vendor%2Fnikic%2Fphp-parser%2Ftest%2FPhpParser%2FNode%2FStmt%2FClassMethodTest.php;h=4000495e608e03e5af8b1827c8d6c047b4ac9599;hp=fa8aed8088e16530fb8a283ef3573361bc95e99d;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/nikic/php-parser/test/PhpParser/Node/Stmt/ClassMethodTest.php b/vendor/nikic/php-parser/test/PhpParser/Node/Stmt/ClassMethodTest.php index fa8aed808..4000495e6 100644 --- a/vendor/nikic/php-parser/test/PhpParser/Node/Stmt/ClassMethodTest.php +++ b/vendor/nikic/php-parser/test/PhpParser/Node/Stmt/ClassMethodTest.php @@ -1,22 +1,27 @@ - constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier)) - )); + ]); $this->assertTrue($node->{'is' . $modifier}()); } public function testNoModifiers() { - $node = new ClassMethod('foo', array('type' => 0)); + $node = new ClassMethod('foo', ['type' => 0]); $this->assertTrue($node->isPublic()); $this->assertFalse($node->isProtected()); @@ -24,17 +29,18 @@ class ClassMethodTest extends \PHPUnit_Framework_TestCase $this->assertFalse($node->isAbstract()); $this->assertFalse($node->isFinal()); $this->assertFalse($node->isStatic()); + $this->assertFalse($node->isMagic()); } public function provideModifiers() { - return array( - array('public'), - array('protected'), - array('private'), - array('abstract'), - array('final'), - array('static'), - ); + return [ + ['public'], + ['protected'], + ['private'], + ['abstract'], + ['final'], + ['static'], + ]; } /** @@ -42,22 +48,77 @@ class ClassMethodTest extends \PHPUnit_Framework_TestCase * * @dataProvider implicitPublicModifiers * - * @param integer $modifier Node type modifier + * @param string $modifier Node type modifier */ - public function testImplicitPublic($modifier) + public function testImplicitPublic(string $modifier) { - $node = new ClassMethod('foo', array( + $node = new ClassMethod('foo', [ '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'), - ); + return [ + ['abstract'], + ['final'], + ['static'], + ]; + } + + /** + * @dataProvider provideMagics + * + * @param string $name Node name + */ + public function testMagic(string $name) { + $node = new ClassMethod($name); + $this->assertTrue($node->isMagic(), 'Method should be magic'); + } + + public function provideMagics() { + return [ + ['__construct'], + ['__DESTRUCT'], + ['__caLL'], + ['__callstatic'], + ['__get'], + ['__set'], + ['__isset'], + ['__unset'], + ['__sleep'], + ['__wakeup'], + ['__tostring'], + ['__set_state'], + ['__clone'], + ['__invoke'], + ['__debuginfo'], + ]; + } + + public function testFunctionLike() { + $param = new Param(new Variable('a')); + $type = new Name('Foo'); + $return = new Return_(new Variable('a')); + $method = new ClassMethod('test', [ + 'byRef' => false, + 'params' => [$param], + 'returnType' => $type, + 'stmts' => [$return], + ]); + + $this->assertFalse($method->returnsByRef()); + $this->assertSame([$param], $method->getParams()); + $this->assertSame($type, $method->getReturnType()); + $this->assertSame([$return], $method->getStmts()); + + $method = new ClassMethod('test', [ + 'byRef' => true, + 'stmts' => null, + ]); + + $this->assertTrue($method->returnsByRef()); + $this->assertNull($method->getStmts()); } }