Do not add the package root to Loader::$dirs under Composer.

files autoload still registers Loader::autoload() so Flight::path() works. Composer PSR-4 already loads flight\*. Reset leftover path() dirs in AutoloadTest so LoaderTest can assert the exact list.
pull/725/head
Ambrose Casanova 7 days ago
parent 2880142083
commit 13af0cb63c

@ -9,6 +9,7 @@ require_once __DIR__ . '/core/Loader.php';
if (file_exists(__DIR__ . '/../vendor/autoload.php')) { if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
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__)]);

@ -5,9 +5,11 @@ declare(strict_types=1);
namespace tests; namespace tests;
use Flight; use Flight;
use flight\core\Loader;
use flight\Engine; use flight\Engine;
use tests\classes\User; use tests\classes\User;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use ReflectionClass;
class AutoloadTest extends TestCase class AutoloadTest extends TestCase
{ {
@ -19,6 +21,17 @@ class AutoloadTest extends TestCase
$this->app->path(__DIR__ . '/classes'); $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 // Autoload a class
public function testAutoload(): void public function testAutoload(): void
{ {

Loading…
Cancel
Save