* Updated build scripts to handle gitless environments a little better * PDO shell plugin improvements * More tests
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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") ],
 | 
						|
        ];
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @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;
 | 
						|
 | 
						|
}
 |