2021-12-11 00:44:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Spark\Environment;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ScriptRunnerTest extends \PhpUnit\Framework\TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider stringExpansionData
|
|
|
|
* @covers ScriptRunner::expandString
|
|
|
|
*/
|
|
|
|
public function testStringExpansion($source, $expect)
|
|
|
|
{
|
|
|
|
$runner = new ScriptRunner();
|
|
|
|
$expanded = $runner->expandString($source);
|
|
|
|
return $this->assertEquals($expect, $expanded);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function stringExpansionData()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[ 'Hello World!', 'Hello World!' ],
|
|
|
|
[ '${testenv}', '' ],
|
|
|
|
[ '${PATH}', getenv("PATH") ],
|
|
|
|
[ 'Greetings ${USER}', 'Greetings '.getenv("USER") ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-12-17 11:51:29 +00:00
|
|
|
/**
|
|
|
|
* @covers ScriptRunner::defineScript
|
|
|
|
* @covers ScriptRunner::evalutateDefinedScript
|
|
|
|
*/
|
|
|
|
public function testDefiningAndCallingScript()
|
|
|
|
{
|
|
|
|
$runner = new ScriptRunner(true);
|
|
|
|
$runner->defineScript('test1', __CLASS__."::call1");
|
|
|
|
$runner->defineScript('test2', [ __CLASS__."::call2" ]);
|
|
|
|
|
|
|
|
$this->assertFalse(self::$call1);
|
|
|
|
$runner->evaluateDefinedScript('test1');
|
|
|
|
$this->assertTrue(self::$call1);
|
|
|
|
|
|
|
|
$this->assertFalse(self::$call2);
|
|
|
|
$runner->evaluateDefinedScript('test2');
|
|
|
|
$this->assertTrue(self::$call2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function call1()
|
|
|
|
{ self::$call1 = true; }
|
|
|
|
|
|
|
|
public static function call2()
|
|
|
|
{ self::$call2 = true; }
|
|
|
|
|
|
|
|
private static bool $call1 = false;
|
|
|
|
private static bool $call2 = false;
|
|
|
|
|
2021-12-11 00:44:01 +00:00
|
|
|
}
|