Misc fixes

* Updated build scripts to handle gitless environments a little
  better
* PDO shell plugin improvements
* More tests
This commit is contained in:
2021-12-17 12:51:29 +01:00
parent 1eab339347
commit 0f45219747
10 changed files with 165 additions and 8 deletions

View 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());
}
}

View File

@ -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;
}

View 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()
{
}
}