Misc fixes
* Updated build scripts to handle gitless environments a little better * PDO shell plugin improvements * More tests
This commit is contained in:
42
tests/Environment/EnvironmentTest.php
Normal file
42
tests/Environment/EnvironmentTest.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Spark\Environment;
|
||||
|
||||
class EnvironmentTest extends \PhpUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @covers Environment::createFromDirectory
|
||||
* @covers Environment::getProjectDirectory
|
||||
*/
|
||||
public function testCreatingEnvironmentByTraversing()
|
||||
{
|
||||
$env = Environment::createFromDirectory(__DIR__, true);
|
||||
|
||||
$this->assertInstanceOf(Environment::class, $env);
|
||||
$this->assertEquals(dirname(__DIR__), $env->getProjectDirectory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Environment::createFromDirectory
|
||||
*/
|
||||
public function testFailingToCreatingEnvironmentFromMissingConfig()
|
||||
{
|
||||
$env = Environment::createFromDirectory(__DIR__);
|
||||
|
||||
$this->assertNull($env);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Environment::createFromDirectory
|
||||
* @covers Environment::getProjectDirectory
|
||||
*/
|
||||
public function testCreatingEnvironmentDirectly()
|
||||
{
|
||||
$env = Environment::createFromDirectory(__DIR__."/..");
|
||||
|
||||
$this->assertInstanceOf(Environment::class, $env);
|
||||
$this->assertEquals(dirname(__DIR__), $env->getProjectDirectory());
|
||||
}
|
||||
|
||||
}
|
@ -27,4 +27,32 @@ class ScriptRunnerTest extends \PhpUnit\Framework\TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
}
|
||||
|
27
tests/Resource/ResourceManagerTest.php
Normal file
27
tests/Resource/ResourceManagerTest.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Spark\Resource;
|
||||
|
||||
|
||||
class ResourceManagerTest extends \PhpUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @covers ResourceManager::registerResourceType
|
||||
*/
|
||||
public function testRegisteringResourceTypes()
|
||||
{
|
||||
$manager = new ResourceManager();
|
||||
$manager->registerResourceType('foo', FooType::class);
|
||||
|
||||
$types = $manager->getAllResourceTypes();
|
||||
$this->assertEquals( ['foo'=>FooType::class], $types );
|
||||
}
|
||||
}
|
||||
|
||||
class FooType extends ResourceType
|
||||
{
|
||||
public function info()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user