Ejemplo n.º 1
0
function manual()
{
    $a = new ServiceA();
    $b = new ServiceB();
    $c = new ServiceC();
    $d = new ServiceD();
    $e = new ServiceE();
    $b->serviceA = $a;
    $c->serviceA = $a;
    $c->serviceB = $b;
    $d->serviceA = $a;
    $d->serviceB = $b;
    $d->serviceC = $c;
    $e->serviceA = $a;
    $e->serviceB = $b;
    $e->serviceC = $c;
    $e->serviceD = $d;
    for ($i = 0; $i < ITERATIONS; $i++) {
        $obj = new MyObject();
        $obj->serviceA = $a;
        $obj->serviceB = $b;
        $obj->serviceC = $c;
        $obj->setServiceD($d);
        $obj->setServiceE($e);
        $obj->doSomething();
    }
}
Ejemplo n.º 2
0
 function testAttachedMethod()
 {
     $myObject = new MyObject();
     try {
         $this->assertEquals('Hello World!', $myObject->helloWorld());
         $this->hasFailed();
     } catch (RecessException $e) {
         // Success
     }
     $attachedMethodProvider = new MyNewClassMethodProvider();
     MyObject::attachMethod('MyObject', 'helloWorld', $attachedMethodProvider, 'callMe');
     try {
         $this->assertEquals($myObject->helloWorld(), 'Hello World!');
         // Success
     } catch (RecessException $e) {
         $this->hasFailed();
     }
 }
Ejemplo n.º 3
0
<?php

class MyObject
{
    function fail()
    {
        throw new Exception();
    }
    function __construct()
    {
        self::fail();
        echo __METHOD__ . "() Must not be reached\n";
    }
    function __destruct()
    {
        echo __METHOD__ . "() Must not be called\n";
    }
    static function test()
    {
        try {
            new MyObject();
        } catch (Exception $e) {
            echo "Caught\n";
        }
    }
}
MyObject::test();
?>
===DONE===
Ejemplo n.º 4
0
<?php

class MyObject
{
    public static $myStaticVar = 0;
    function myMethod()
    {
        self::$myStaticVar += 2;
        echo self::$myStaticVar . "<br/>";
    }
}
class MyOtherObject extends MyObject
{
    public static $myStaticVar = 0;
    function myOtherMethod()
    {
        echo parent::$myStaticVar . "<br/>";
        echo self::$myStaticVar . "<br/>";
    }
}
$instance1 = new MyObject();
$instance1->myMethod();
$instance2 = new MyObject();
$instance2->myMethod();
$instance3 = new myOtherObject();
$instance3->myOtherMethod();
Ejemplo n.º 5
0
 function myMethod()
 {
     echo "New Functionality";
     parent::myMethod();
 }
Ejemplo n.º 6
0
 function testSingleArgumentWrappedMethod()
 {
     $obj = new MyObject();
     $this->assertEquals('Arg:Hello World', $obj->singleArgument('Hello World'));
 }
Ejemplo n.º 7
0
<?php

require "tests.php";
require "director_extend.php";
// No new functions
check::functions(array(spobject_getfoobar, spobject_dummy, spobject_exceptionmethod));
// No new classes
check::classes(array(SpObject));
// now new vars
check::globals(array());
class MyObject extends SpObject
{
    function getFoo()
    {
        return 123;
    }
}
$m = new MyObject();
check::equal($m->dummy(), 666, "1st call");
check::equal($m->dummy(), 666, "2st call");
// Locked system
check::done();