Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions shared/Commands/DemoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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()
);
}
}

/**
Expand Down Expand Up @@ -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']);
Expand Down
8 changes: 3 additions & 5 deletions tests/Feature/AppTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions tests/Feature/modules/Api/AuthControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,8 +16,8 @@ public function setUp(): void
{
parent::setUp();

Request::flush();
Response::flush();
request()->flush();
response()->flush();

$this->faker = Factory::create();
}
Expand Down
6 changes: 2 additions & 4 deletions tests/Feature/modules/Api/CommentControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -26,8 +24,8 @@ public function setUp(): void

$this->post = $postData[0];

Request::flush();
Response::flush();
request()->flush();
response()->flush();
}

public function tearDown(): void
Expand Down
3 changes: 1 addition & 2 deletions tests/Feature/modules/Api/PostControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,7 +12,7 @@ public function setUp(): void
{
parent::setUp();

Request::flush();
request()->flush();
}

public function tearDown(): void
Expand Down
3 changes: 1 addition & 2 deletions tests/Feature/modules/Api/PostManagementControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +16,7 @@ public function setUp(): void

$this->tokens = $this->signInAndGetTokens();

Request::flush();
request()->flush();
}

public function tearDown(): void
Expand Down
3 changes: 1 addition & 2 deletions tests/Helpers/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Loading