php-parser/test/PhpParser/Node/Stmt/ClassTest.php

62 lines
1.7 KiB
PHP
Raw Normal View History

<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
2017-04-27 18:14:07 +02:00
use PHPUnit\Framework\TestCase;
class ClassTest extends TestCase
{
public function testIsAbstract() {
2017-08-13 14:35:03 +02:00
$class = new Class_('Foo', ['type' => Class_::MODIFIER_ABSTRACT]);
$this->assertTrue($class->isAbstract());
$class = new Class_('Foo');
$this->assertFalse($class->isAbstract());
}
public function testIsFinal() {
2017-08-13 14:35:03 +02:00
$class = new Class_('Foo', ['type' => Class_::MODIFIER_FINAL]);
$this->assertTrue($class->isFinal());
$class = new Class_('Foo');
$this->assertFalse($class->isFinal());
}
public function testGetMethods() {
2017-08-13 14:35:03 +02:00
$methods = [
new ClassMethod('foo'),
new ClassMethod('bar'),
new ClassMethod('fooBar'),
2017-08-13 14:35:03 +02:00
];
$class = new Class_('Foo', [
'stmts' => [
new TraitUse([]),
$methods[0],
2017-08-13 14:35:03 +02:00
new ClassConst([]),
$methods[1],
2017-08-13 14:35:03 +02:00
new Property(0, []),
$methods[2],
2017-08-13 14:35:03 +02:00
]
]);
2014-09-30 20:38:09 +02:00
$this->assertSame($methods, $class->getMethods());
}
public function testGetMethod() {
$methodConstruct = new ClassMethod('__CONSTRUCT');
$methodTest = new ClassMethod('test');
2017-08-13 14:35:03 +02:00
$class = new Class_('Foo', [
'stmts' => [
new ClassConst([]),
$methodConstruct,
2017-08-13 14:35:03 +02:00
new Property(0, []),
$methodTest,
2017-08-13 14:35:03 +02:00
]
]);
$this->assertSame($methodConstruct, $class->getMethod('__construct'));
$this->assertSame($methodTest, $class->getMethod('test'));
$this->assertNull($class->getMethod('nonExisting'));
}
}