2017-11-02 18:56:01 +01:00
|
|
|
<?php declare(strict_types=1);
|
2012-07-07 16:08:37 +02:00
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser\Node\Stmt;
|
|
|
|
|
2019-01-19 11:18:00 +01:00
|
|
|
class PropertyTest extends \PHPUnit\Framework\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 Property(
|
|
|
|
constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier)),
|
2017-08-13 14:35:03 +02:00
|
|
|
[] // invalid
|
2012-07-07 16:08:37 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertTrue($node->{'is' . $modifier}());
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:18:49 +01:00
|
|
|
public function testNoModifiers() {
|
2017-08-13 14:35:03 +02:00
|
|
|
$node = new Property(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->isStatic());
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-05 20:15:02 +02:00
|
|
|
public function testStaticImplicitlyPublic() {
|
2017-08-13 14:35:03 +02:00
|
|
|
$node = new Property(Class_::MODIFIER_STATIC, []);
|
2015-07-05 20:15:02 +02:00
|
|
|
$this->assertTrue($node->isPublic());
|
|
|
|
$this->assertFalse($node->isProtected());
|
|
|
|
$this->assertFalse($node->isPrivate());
|
|
|
|
$this->assertTrue($node->isStatic());
|
|
|
|
}
|
|
|
|
|
2012-07-07 16:08:37 +02:00
|
|
|
public function provideModifiers() {
|
2017-08-13 14:35:03 +02:00
|
|
|
return [
|
|
|
|
['public'],
|
|
|
|
['protected'],
|
|
|
|
['private'],
|
|
|
|
['static'],
|
|
|
|
];
|
2012-07-07 16:08:37 +02:00
|
|
|
}
|
2014-11-13 20:18:49 +01:00
|
|
|
}
|