fix(test): set fulltext search driver to tntsearch

This commit is contained in:
Phan An 2022-07-29 10:26:18 +02:00
parent 3f5d95b0af
commit 2835bfedae
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC
3 changed files with 10 additions and 21 deletions

View file

@ -4,7 +4,6 @@ namespace App\Providers;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Throwable;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
class RouteServiceProvider extends ServiceProvider class RouteServiceProvider extends ServiceProvider
@ -33,19 +32,15 @@ class RouteServiceProvider extends ServiceProvider
private static function getApiVersion(): ?string private static function getApiVersion(): ?string
{ {
try { // In the test environment, the route service provider is loaded _before_ the request is made,
// In the test environment, the route service provider is loaded _before_ the request is made, // so we can't rely on the header.
// so we can't rely on the header. // Instead, we manually set the API version as an env variable in applicable test cases.
// Instead, we manually set the API version as an env variable in applicable test cases. $version = app()->runningUnitTests() ? env('X_API_VERSION') : request()->header('X-Api-Version');
$version = app()->runningUnitTests() ? env('X_API_VERSION') : request()->header('X-Api-Version');
if ($version) { if ($version) {
Assert::oneOf($version, ['v6']); Assert::oneOf($version, ['v6']);
}
return $version;
} catch (Throwable) {
return null;
} }
return $version;
} }
} }

View file

@ -36,7 +36,7 @@
<env name="APP_URL" value="http://localhost/"/> <env name="APP_URL" value="http://localhost/"/>
<env name="APP_KEY" value="16efa6c23c2e8c705826b0e66778fbe7"/> <env name="APP_KEY" value="16efa6c23c2e8c705826b0e66778fbe7"/>
<env name="CACHE_DRIVER" value="array"/> <env name="CACHE_DRIVER" value="array"/>
<env name="SCOUT_DRIVER" value="database"/> <env name="SCOUT_DRIVER" value="tntsearch"/> <!-- "database" driver doesn't support SQLite -->
<env name="SESSION_DRIVER" value="array"/> <env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/> <env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/> <env name="DB_CONNECTION" value="sqlite"/>

View file

@ -6,7 +6,6 @@ use App\Console\Kernel;
use App\Models\User; use App\Models\User;
use Illuminate\Contracts\Console\Kernel as Artisan; use Illuminate\Contracts\Console\Kernel as Artisan;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Throwable;
trait CreatesApplication trait CreatesApplication
{ {
@ -29,12 +28,7 @@ trait CreatesApplication
private function prepareForTests(): void private function prepareForTests(): void
{ {
try { $this->artisan->call('migrate');
$this->artisan->call('migrate');
} catch (Throwable $e) {
\Log::error($e); // @phpcs:ignore
throw $e;
}
if (!User::count()) { if (!User::count()) {
$this->artisan->call('db:seed'); $this->artisan->call('db:seed');