|
|
|
@ -4,10 +4,12 @@ declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
namespace tests;
|
|
|
|
namespace tests;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use flight\core\Loader;
|
|
|
|
use flight\core\Loader;
|
|
|
|
use tests\classes\Factory;
|
|
|
|
use tests\classes\Factory;
|
|
|
|
use tests\classes\User;
|
|
|
|
use tests\classes\User;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
use ReflectionClass;
|
|
|
|
use tests\classes\TesterClass;
|
|
|
|
use tests\classes\TesterClass;
|
|
|
|
|
|
|
|
|
|
|
|
class LoaderTest extends TestCase
|
|
|
|
class LoaderTest extends TestCase
|
|
|
|
@ -17,7 +19,6 @@ class LoaderTest extends TestCase
|
|
|
|
protected function setUp(): void
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->loader = new Loader();
|
|
|
|
$this->loader = new Loader();
|
|
|
|
$this->loader->autoload(true, __DIR__ . '/classes');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Autoload a class
|
|
|
|
// Autoload a class
|
|
|
|
@ -85,7 +86,7 @@ class LoaderTest extends TestCase
|
|
|
|
// Gets an object from a factory method
|
|
|
|
// Gets an object from a factory method
|
|
|
|
public function testRegisterUsingCallable(): void
|
|
|
|
public function testRegisterUsingCallable(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->loader->register('e', ['\tests\classes\Factory', 'create']);
|
|
|
|
$this->loader->register('e', Closure::fromCallable([Factory::class, 'create']));
|
|
|
|
|
|
|
|
|
|
|
|
$obj = $this->loader->load('e');
|
|
|
|
$obj = $this->loader->load('e');
|
|
|
|
|
|
|
|
|
|
|
|
@ -140,29 +141,25 @@ class LoaderTest extends TestCase
|
|
|
|
|
|
|
|
|
|
|
|
public function testAddDirectoryAsArray(): void
|
|
|
|
public function testAddDirectoryAsArray(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$loader = new class extends Loader {
|
|
|
|
$loader = new Loader();
|
|
|
|
public function getDirectories()
|
|
|
|
$loader::addDirectory([__DIR__ . '/classes']);
|
|
|
|
{
|
|
|
|
|
|
|
|
return self::$dirs;
|
|
|
|
$dirsProperty = (new ReflectionClass(Loader::class))->getProperty('dirs');
|
|
|
|
}
|
|
|
|
$dirsProperty->setAccessible(true);
|
|
|
|
};
|
|
|
|
$dirs = $dirsProperty->getValue($loader);
|
|
|
|
$loader->addDirectory([__DIR__ . '/classes']);
|
|
|
|
|
|
|
|
self::assertEquals([
|
|
|
|
self::assertEquals([__DIR__ . DIRECTORY_SEPARATOR . 'classes'], $dirs);
|
|
|
|
dirname(__DIR__),
|
|
|
|
|
|
|
|
__DIR__ . '/classes'
|
|
|
|
|
|
|
|
], $loader->getDirectories());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testV2ClassLoading(): void
|
|
|
|
public function testV2ClassLoading(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$loader = new class extends Loader {
|
|
|
|
$loader = new Loader();
|
|
|
|
public static function getV2ClassLoading()
|
|
|
|
|
|
|
|
{
|
|
|
|
$v2ClassLoadingProperty = (new ReflectionClass(Loader::class))->getProperty('v2ClassLoading');
|
|
|
|
return self::$v2ClassLoading;
|
|
|
|
$v2ClassLoadingProperty->setAccessible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
$this->assertTrue($v2ClassLoadingProperty->getValue($loader));
|
|
|
|
$this->assertTrue($loader::getV2ClassLoading());
|
|
|
|
|
|
|
|
$loader::setV2ClassLoading(false);
|
|
|
|
$loader::setV2ClassLoading(false);
|
|
|
|
$this->assertFalse($loader::getV2ClassLoading());
|
|
|
|
$this->assertFalse($v2ClassLoadingProperty->getValue($loader));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|