--TEST-- Environement parent --FILE-- <?php use php\lang\Environment; class X { static $foo = 'bar'; } function test() { return 'foo'; } $env = new Environment(Environment::current()); $env->execute(function () { ob_implicit_flush(true); var_dump(test()); var_dump(X::$foo); }); $env = new Environment(null); $env->execute(function () { ob_implicit_flush(true); echo "class 'X' exists - " . (class_exists('X') ? 'true' : 'false'), "\n"; echo "function 'test' exists - " . (function_exists('test') ? 'true' : 'false'), "\n"; }); ?> --EXPECT-- string(3) "foo" string(3) "bar" class 'X' exists - false function 'test' exists - false
--TEST-- Shared basic test --FILE-- <?php use php\lang\Environment; use php\util\Shared; Shared::resetAll(); ob_implicit_flush(1); $value = Shared::value('foobar'); var_dump($value->isEmpty()); var_dump($value->get()); $env1 = new Environment(); $env2 = new Environment(); $value->set('foobar'); $env1->execute(function () { var_dump(Shared::value('foobar')->get()); }); $env2->execute(function () { var_dump(Shared::value('foobar')->get()); }); ?> --EXPECT-- bool(true) NULL string(6) "foobar" string(6) "foobar"
--TEST-- Environement test --FILE-- <?php use php\lang\Environment; $env = new Environment(); var_dump($env->execute(function () { var_dump("success1"); return 'success2'; })); ?> --EXPECT-- string(8) "success1" string(8) "success2"
--TEST-- Environement defineConstant --FILE-- <?php use php\lang\Environment; class X { static $foo = FOOBAR; } define('FOOBAR', 'fail'); $env = new Environment(); $env->execute(function () { var_dump(FOOBAR); }); $env->defineConstant('FOOBAR', 'success'); $env->importClass('X'); $env->execute(function () { var_dump(FOOBAR); var_dump(X::$foo); }); ?> --EXPECTF-- string(6) "FOOBAR" string(7) "success" string(7) "success" Notice: Use of undefined constant FOOBAR - assumed 'FOOBAR' in %s on line %d at pos %d
$env1 = new Environment(); $env2 = new Environment(); function foobar($value) { return Shared::value('foobar', function () use($value) { return $value; }); } $env1->importFunction('foobar'); $env2->importFunction('foobar'); $env1->execute(function () { ob_implicit_flush(1); var_dump(foobar('x')->get()); }); $env2->execute(function () { ob_implicit_flush(1); var_dump(foobar('y')->get()); }); var_dump(Shared::reset('foobar')); $env2->execute(function () { ob_implicit_flush(1); var_dump(foobar('y')->get()); }); ?> --EXPECTF-- string(1) "x" string(1) "x" object(php\util\SharedValue)#%d (1) { ["*value"]=> string(1) "x" } string(1) "y"
--TEST-- Environement import --FILE-- <?php ob_implicit_flush(true); use php\lang\Environment; class Foo { } function bar() { } $env = new Environment(); $env->execute(function () { ob_implicit_flush(true); var_dump('class Foo exits: ', class_exists('Foo')); var_dump('function bar exits: ', function_exists('bar')); }); echo "\nImport ...", "\n"; $env->importClass('Foo'); $env->importFunction('bar'); $env->execute(function () { ob_implicit_flush(true); var_dump('class Foo exits: ', class_exists('Foo')); var_dump('function bar exits: ', function_exists('bar')); }); ?> --EXPECT-- string(17) "class Foo exits: " bool(false) string(20) "function bar exits: "
--TEST-- Environement current --FILE-- <?php use php\lang\Environment; $global = 'foobar'; $env = Environment::current(); $env->execute(function () { ob_implicit_flush(true); global $global; var_dump($global); }); $env = new Environment(); $env->execute(function () { ob_implicit_flush(true); global $global; var_dump($global); }); ?> --EXPECT-- string(6) "foobar" NULL