コード例 #1
0
ファイル: SafeDecoratorTest.php プロジェクト: robo47/symfony
 public function testMagicCall()
 {
     $safe = new SafeDecorator(new TestClass2());
     $this->assertEquals('ok', $safe->doSomething(), '->__call() invokes the embedded method');
 }
コード例 #2
0
    public $foo = 'bar';
}
$safe = new SafeDecorator(new TestClass1());
$t->is($safe->foo, 'bar', '->__get() returns the object parameter');
$safe->foo = 'baz';
$t->is($safe->foo, 'baz', '->__set() sets the object parameter');
// ->__call()
$t->diag('->__call()');
class TestClass2
{
    public function doSomething()
    {
        return 'ok';
    }
}
$safe = new SafeDecorator(new TestClass2());
$t->is($safe->doSomething(), 'ok', '->__call() invokes the embedded method');
// ->__isset() ->__unset()
$t->diag('->__isset() ->__unset()');
class TestClass3
{
    public $boolValue = true, $nullValue = null;
}
$safe = new SafeDecorator(new TestClass3());
$t->is(isset($safe->boolValue), true, '->__isset() returns true if the property is not null');
$t->is(isset($safe->nullValue), false, '->__isset() returns false if the property is null');
$t->is(isset($safe->undefinedValue), false, '->__isset() returns false if the property does not exist');
unset($safe->boolValue);
$t->is(isset($safe->boolValue), false, '->__unset() unsets the embedded property');
// Iterator
$t->diag('Iterator');