From edd63e1f851d48da6204bf24ca942b0246250d66 Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Mon, 20 Apr 2026 15:43:03 +0400 Subject: [PATCH 1/3] Fix DemoCommand compatibility with lazy DI registration in core Made-with: Cursor --- shared/Commands/DemoCommand.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shared/Commands/DemoCommand.php b/shared/Commands/DemoCommand.php index 5908d84..099ebfb 100644 --- a/shared/Commands/DemoCommand.php +++ b/shared/Commands/DemoCommand.php @@ -35,6 +35,7 @@ use Shared\Enums\Role; use Faker\Generator; use ErrorException; +use Quantum\Di\Di; use Faker\Factory; /** @@ -224,6 +225,10 @@ private function initProgressBar(int $steps): ProgressBar */ private function createModule(string $moduleName, string $template, bool $withAssets): void { + if (is_dir(modules_dir() . DS . $moduleName)) { + return; + } + $this->runCommandExternally(self::COMMANDS['module_generate'], [ 'module' => $moduleName, '--yes' => true, @@ -400,7 +405,11 @@ private function updateProgress(ProgressBar $progress, string $message): void */ private function rebuildDatabase(): void { - switch (Database::getInstance()->getConfigs()['driver']) { + if (!Di::isRegistered(Database::class)) { + Di::register(Database::class); + } + + switch (Di::get(Database::class)->getConfigs()['driver']) { case 'mysql': $this->runCommandInternally(self::COMMANDS['migrate'], ['direction' => 'down']); $this->runCommandInternally(self::COMMANDS['migrate'], ['direction' => 'up']); From 628fde5da794b3371b34be5d0705463b99ef250c Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Mon, 20 Apr 2026 18:14:51 +0400 Subject: [PATCH 2/3] Fix PHPUnit tests for DI-based Request/Response API Replace static calls with instance calls via helper functions and recreate the app per request in AppTestCase to ensure a fresh DI container with bootstrapped Environment and Config. Made-with: Cursor --- tests/Feature/AppTestCase.php | 8 +++----- tests/Feature/modules/Api/AuthControllerTest.php | 6 ++---- tests/Feature/modules/Api/CommentControllerTest.php | 6 ++---- tests/Feature/modules/Api/PostControllerTest.php | 3 +-- .../Feature/modules/Api/PostManagementControllerTest.php | 3 +-- tests/Helpers/functions.php | 3 +-- 6 files changed, 10 insertions(+), 19 deletions(-) diff --git a/tests/Feature/AppTestCase.php b/tests/Feature/AppTestCase.php index 56e9856..37c2e76 100644 --- a/tests/Feature/AppTestCase.php +++ b/tests/Feature/AppTestCase.php @@ -5,9 +5,7 @@ use PHPUnit\Framework\TestCase; use Quantum\App\Enums\AppType; use Quantum\Http\Response; -use Quantum\Http\Request; use Quantum\App\App; -use Quantum\Di\Di; class AppTestCase extends TestCase { @@ -42,10 +40,10 @@ public function request( array $headers = [], array $files = [] ): Response { - Di::resetContainer(); - Request::create($method, $url, $params, $headers, $files); + self::$app = createApp(AppType::WEB, PROJECT_ROOT); + request()->create($method, $url, $params, $headers, $files); self::$app->start(); - return new Response(); + return response(); } protected function signInAndGetTokens(): array diff --git a/tests/Feature/modules/Api/AuthControllerTest.php b/tests/Feature/modules/Api/AuthControllerTest.php index f52f79b..2d08afd 100644 --- a/tests/Feature/modules/Api/AuthControllerTest.php +++ b/tests/Feature/modules/Api/AuthControllerTest.php @@ -4,8 +4,6 @@ use Quantum\Model\Factories\ModelFactory; use Quantum\Tests\Feature\AppTestCase; -use Quantum\Http\Response; -use Quantum\Http\Request; use Shared\Models\User; use Faker\Generator; use Faker\Factory; @@ -18,8 +16,8 @@ public function setUp(): void { parent::setUp(); - Request::flush(); - Response::flush(); + request()->flush(); + response()->flush(); $this->faker = Factory::create(); } diff --git a/tests/Feature/modules/Api/CommentControllerTest.php b/tests/Feature/modules/Api/CommentControllerTest.php index 5422869..a6f906c 100644 --- a/tests/Feature/modules/Api/CommentControllerTest.php +++ b/tests/Feature/modules/Api/CommentControllerTest.php @@ -5,8 +5,6 @@ use Quantum\Model\Factories\ModelFactory; use Quantum\Tests\Feature\AppTestCase; use Shared\Models\Comment; -use Quantum\Http\Response; -use Quantum\Http\Request; class CommentControllerTest extends AppTestCase { @@ -26,8 +24,8 @@ public function setUp(): void $this->post = $postData[0]; - Request::flush(); - Response::flush(); + request()->flush(); + response()->flush(); } public function tearDown(): void diff --git a/tests/Feature/modules/Api/PostControllerTest.php b/tests/Feature/modules/Api/PostControllerTest.php index 8d84fad..59232dc 100644 --- a/tests/Feature/modules/Api/PostControllerTest.php +++ b/tests/Feature/modules/Api/PostControllerTest.php @@ -4,7 +4,6 @@ use Quantum\Model\Factories\ModelFactory; use Quantum\Tests\Feature\AppTestCase; -use Quantum\Http\Request; use Shared\Models\Post; class PostControllerTest extends AppTestCase @@ -13,7 +12,7 @@ public function setUp(): void { parent::setUp(); - Request::flush(); + request()->flush(); } public function tearDown(): void diff --git a/tests/Feature/modules/Api/PostManagementControllerTest.php b/tests/Feature/modules/Api/PostManagementControllerTest.php index fc115b9..4af5df6 100644 --- a/tests/Feature/modules/Api/PostManagementControllerTest.php +++ b/tests/Feature/modules/Api/PostManagementControllerTest.php @@ -4,7 +4,6 @@ use Quantum\Model\Factories\ModelFactory; use Quantum\Tests\Feature\AppTestCase; -use Quantum\Http\Request; use Shared\Models\Post; class PostManagementControllerTest extends AppTestCase @@ -17,7 +16,7 @@ public function setUp(): void $this->tokens = $this->signInAndGetTokens(); - Request::flush(); + request()->flush(); } public function tearDown(): void diff --git a/tests/Helpers/functions.php b/tests/Helpers/functions.php index d4618a1..0755c85 100644 --- a/tests/Helpers/functions.php +++ b/tests/Helpers/functions.php @@ -13,7 +13,6 @@ use Quantum\Hasher\Hasher; use Shared\DTOs\PostDTO; use Quantum\Router\Route; -use Quantum\Http\Request; use Shared\Models\User; use Quantum\App\App; use Faker\Factory; @@ -55,7 +54,7 @@ function createModule(string $moduleName, string $template, bool $withAssets = f }); $route->module($moduleName); $matchedRoute = new MatchedRoute($route, []); - Request::setMatchedRoute($matchedRoute); + request()->setMatchedRoute($matchedRoute); ob_end_clean(); } From 319c5cbc5652fefa6f7a1d113b2d559341c944c3 Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Mon, 20 Apr 2026 19:39:22 +0400 Subject: [PATCH 3/3] Remove silent skip in createModule, surface module:generate errors Let module:generate handle its own existence checks instead of silently skipping on is_dir(). Catch ProcessFailedException to surface a clean error message. Made-with: Cursor --- shared/Commands/DemoCommand.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/shared/Commands/DemoCommand.php b/shared/Commands/DemoCommand.php index 099ebfb..81d24d7 100644 --- a/shared/Commands/DemoCommand.php +++ b/shared/Commands/DemoCommand.php @@ -16,6 +16,7 @@ namespace Shared\Commands; +use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Console\Exception\ExceptionInterface; use Quantum\HttpClient\Exceptions\HttpClientException; use Symfony\Component\Console\Helper\ProgressBar; @@ -33,6 +34,7 @@ use Ottaviano\Faker\Gravatar; use ReflectionException; use Shared\Enums\Role; +use RuntimeException; use Faker\Generator; use ErrorException; use Quantum\Di\Di; @@ -225,16 +227,18 @@ private function initProgressBar(int $steps): ProgressBar */ private function createModule(string $moduleName, string $template, bool $withAssets): void { - if (is_dir(modules_dir() . DS . $moduleName)) { - return; + try { + $this->runCommandExternally(self::COMMANDS['module_generate'], [ + 'module' => $moduleName, + '--yes' => true, + '--template' => $template, + '--with-assets' => $withAssets, + ]); + } catch (ProcessFailedException $e) { + throw new RuntimeException( + trim($e->getProcess()->getOutput()) ?: $e->getMessage() + ); } - - $this->runCommandExternally(self::COMMANDS['module_generate'], [ - 'module' => $moduleName, - '--yes' => true, - '--template' => $template, - '--with-assets' => $withAssets, - ]); } /**