Beispiel #1
0
    public function testBugWithAssign()
    {
        $classes = array("foo", "bar", "foobar");
        $namespace = safe_eval(Artifex::execute(<<<'EOF'
#* $classes = @$classes
function xxx() {
    return __classes__;
}
EOF
, compact('classes')));
        $fnc = $namespace . '\\xxx';
        $this->assertEquals($fnc(), $classes);
    }
Beispiel #2
0
    public function testDefineScope()
    {
        $vm = Artifex::compile(<<<'EOF'
#* $foo = "foo"
#* $methods = [1, 2]
#* function defineClass($foo, $methods)
class __foo__ {
    #* foreach ($methods as $method) 
    public function set__method__() {
    }
    #* end
}
#* end
EOF
);
        $function = $vm->getFunction("defineClass");
        try {
            /* it fails because the main 
               scope haven't run yet and the variables
               $foo and $methods doens't exists yet */
            $code = $function();
            $this->assertTrue(false);
        } catch (\RuntimeException $e) {
            $this->assertTrue(true);
        }
        $vm->run();
        $code = $function();
        $namespace = safe_eval($code);
        $class = $namespace . '\\foo';
        $this->assertTrue(class_exists($class));
        $this->assertTrue(is_callable($class, 'set1'));
        $this->assertTrue(is_callable($class, 'set2'));
    }