Esempio n. 1
0
 /**
  * @test
  */
 public function defineInterfaceAndUse()
 {
     $className = 'ExampleForInterface';
     $class = new Stagehand_PHP_Class($className);
     $class->defineInterface();
     $propertyA = new Stagehand_PHP_Class_Property('a');
     $methodB = new Stagehand_PHP_Class_Method('b');
     $methodC = new Stagehand_PHP_Class_Method('c');
     $methodC->defineAbstract();
     $methodC->defineStatic();
     $methodD = new Stagehand_PHP_Class_Method('d');
     $methodD->defineProtected();
     $methodE = new Stagehand_PHP_Class_Method('e');
     $methodE->definePrivate();
     $class->addProperty($propertyA);
     $class->addMethod($methodB);
     $class->addMethod($methodC);
     $class->addMethod($methodD);
     $class->addMethod($methodE);
     $class->load();
     $refClass = new ReflectionClass($className);
     $this->assertEquals($refClass->getName(), $className);
     $this->assertTrue($refClass->isInterface());
     $this->assertFalse($refClass->hasProperty('a'));
     $this->assertTrue($refClass->hasMethod('b'));
     $this->assertTrue($refClass->hasMethod('c'));
     $this->assertFalse($refClass->hasMethod('d'));
     $this->assertFalse($refClass->hasMethod('e'));
     $refMethodB = $refClass->getMethod('b');
     $refMethodC = $refClass->getMethod('c');
     $this->assertTrue($refMethodB->isPublic());
     $this->assertTrue($refMethodB->isAbstract());
     $this->assertFalse($refMethodB->isStatic());
     $this->assertTrue($refMethodC->isPublic());
     $this->assertTrue($refMethodC->isAbstract());
     $this->assertTrue($refMethodC->isStatic());
     require_once dirname(__FILE__) . "/ClassTest/ImplementedClass.php";
     $instance = new ImplementedClass();
     $this->assertEquals($instance->b(), 'foo');
     $this->assertEquals(ImplementedClass::c(), 'bar');
 }
Esempio n. 2
0
[expect php]

[file]
<?php 
abstract class AbstractClass
{
    public abstract function test();
}
class ImplementedClass extends AbstractClass
{
    public function test()
    {
        echo "ImplementedClass::test() called.\n";
    }
}
$o = new ImplementedClass();
$o->test();