2012-07-07 16:08:37 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser\Node\Stmt;
|
|
|
|
|
2017-04-27 18:14:07 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class ClassMethodTest extends TestCase
|
2012-07-07 16:08:37 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider provideModifiers
|
|
|
|
*/
|
|
|
|
public function testModifiers($modifier) {
|
2014-02-06 14:44:16 +01:00
|
|
|
$node = new ClassMethod('foo', array(
|
|
|
|
'type' => constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier))
|
2012-07-07 16:08:37 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertTrue($node->{'is' . $modifier}());
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:18:49 +01:00
|
|
|
public function testNoModifiers() {
|
2014-02-06 14:44:16 +01:00
|
|
|
$node = new ClassMethod('foo', array('type' => 0));
|
2012-07-07 16:08:37 +02:00
|
|
|
|
2014-11-13 20:18:49 +01:00
|
|
|
$this->assertTrue($node->isPublic());
|
|
|
|
$this->assertFalse($node->isProtected());
|
|
|
|
$this->assertFalse($node->isPrivate());
|
|
|
|
$this->assertFalse($node->isAbstract());
|
|
|
|
$this->assertFalse($node->isFinal());
|
|
|
|
$this->assertFalse($node->isStatic());
|
2017-04-22 14:37:53 +02:00
|
|
|
$this->assertFalse($node->isMagic());
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideModifiers() {
|
|
|
|
return array(
|
|
|
|
array('public'),
|
|
|
|
array('protected'),
|
|
|
|
array('private'),
|
|
|
|
array('abstract'),
|
|
|
|
array('final'),
|
|
|
|
array('static'),
|
|
|
|
);
|
|
|
|
}
|
2015-07-05 19:01:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks that implicit public modifier detection for method is working
|
|
|
|
*
|
|
|
|
* @dataProvider implicitPublicModifiers
|
|
|
|
*
|
2017-04-26 21:49:22 +02:00
|
|
|
* @param string $modifier Node type modifier
|
2015-07-05 19:01:51 +02:00
|
|
|
*/
|
|
|
|
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'),
|
|
|
|
);
|
|
|
|
}
|
2017-04-22 14:37:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideMagics
|
|
|
|
*
|
|
|
|
* @param string $name Node name
|
|
|
|
*/
|
|
|
|
public function testMagic($name) {
|
|
|
|
$node = new ClassMethod($name);
|
|
|
|
$this->assertTrue($node->isMagic(), 'Method should be magic');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideMagics() {
|
|
|
|
return array(
|
|
|
|
array('__construct'),
|
|
|
|
array('__DESTRUCT'),
|
|
|
|
array('__caLL'),
|
|
|
|
array('__callstatic'),
|
|
|
|
array('__get'),
|
|
|
|
array('__set'),
|
|
|
|
array('__isset'),
|
|
|
|
array('__unset'),
|
|
|
|
array('__sleep'),
|
|
|
|
array('__wakeup'),
|
|
|
|
array('__tostring'),
|
|
|
|
array('__set_state'),
|
|
|
|
array('__clone'),
|
|
|
|
array('__invoke'),
|
|
|
|
array('__debuginfo'),
|
|
|
|
);
|
|
|
|
}
|
2014-11-13 20:18:49 +01:00
|
|
|
}
|