diff --git a/shared/Commands/DemoCommand.php b/shared/Commands/DemoCommand.php index 5908d84..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,8 +34,10 @@ use Ottaviano\Faker\Gravatar; use ReflectionException; use Shared\Enums\Role; +use RuntimeException; use Faker\Generator; use ErrorException; +use Quantum\Di\Di; use Faker\Factory; /** @@ -224,12 +227,18 @@ private function initProgressBar(int $steps): ProgressBar */ private function createModule(string $moduleName, string $template, bool $withAssets): void { - $this->runCommandExternally(self::COMMANDS['module_generate'], [ - 'module' => $moduleName, - '--yes' => true, - '--template' => $template, - '--with-assets' => $withAssets, - ]); + 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() + ); + } } /** @@ -400,7 +409,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']); 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(); }