Merge pull request #725 from flightphp/restore-path-autoloader

Restore Flight::path() autoloading broken in 3.19
pull/728/head v3.19.2
n0nag0n 6 days ago committed by GitHub
commit f617b5c2f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -27,6 +27,9 @@
"ext-json": "*"
},
"autoload": {
"files": [
"flight/autoload.php"
],
"classmap": [
"flight/Flight.php"
],

@ -8,7 +8,8 @@ require_once __DIR__ . '/Flight.php';
require_once __DIR__ . '/core/Loader.php';
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
return require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';
Loader::autoload(true);
} else {
Loader::autoload(true, [dirname(__DIR__)]);
}
Loader::autoload(true, dirname(__DIR__));

@ -4,9 +4,12 @@ declare(strict_types=1);
namespace tests;
use Flight;
use flight\core\Loader;
use flight\Engine;
use tests\classes\User;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
class AutoloadTest extends TestCase
{
@ -18,6 +21,17 @@ class AutoloadTest extends TestCase
$this->app->path(__DIR__ . '/classes');
}
protected function tearDown(): void
{
$dirsProperty = (new ReflectionClass(Loader::class))->getProperty('dirs');
if (PHP_VERSION_ID < 80100) {
$dirsProperty->setAccessible(true);
}
$dirsProperty->setValue(null, []);
}
// Autoload a class
public function testAutoload(): void
{
@ -44,4 +58,17 @@ class AutoloadTest extends TestCase
self::assertNull($test);
}
// Flight::path() must load namespaced classes that Composer PSR-4 does not map
public function testPathAutoloadsNamespacedClassOutsideComposerPsr4(): void
{
$class = \app\middleware\Something::class;
self::assertFalse(class_exists($class));
Flight::path(__DIR__ . '/path_autoload_fixtures');
self::assertTrue(class_exists($class));
self::assertTrue(class_exists(Engine::class));
}
}

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace app\middleware;
class Something
{
}
Loading…
Cancel
Save