Lint migrations
This commit is contained in:
parent
b66f15e2a7
commit
7e5c4a7aff
|
@ -7,6 +7,7 @@ use Illuminate\Http\RedirectResponse;
|
|||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Telescope\Telescope;
|
||||
use Zoomyboy\LaravelNami\Authentication\NamiGuard;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
|
@ -19,6 +20,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
public function register()
|
||||
{
|
||||
JsonResource::withoutWrapping();
|
||||
Telescope::ignoreMigrations();
|
||||
|
||||
\Inertia::share('search', request()->query('search', ''));
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateGendersTable extends Migration
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ class CreateGendersTable extends Migration
|
|||
Schema::create('genders', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->integer('nami_id');
|
||||
$table->unsignedInteger('nami_id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateRegionsTable extends Migration
|
||||
{
|
||||
|
@ -17,7 +17,7 @@ class CreateRegionsTable extends Migration
|
|||
$table->id();
|
||||
$table->string('name');
|
||||
$table->boolean('is_null');
|
||||
$table->integer('nami_id')->nullable();
|
||||
$table->unsignedInteger('nami_id')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateConfessionsTable extends Migration
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ class CreateConfessionsTable extends Migration
|
|||
Schema::create('confessions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->integer('nami_id')->nullable();
|
||||
$table->unsignedInteger('nami_id')->nullable();
|
||||
$table->boolean('is_null');
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateSubscriptionsTable extends Migration
|
||||
{
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateTelescopeEntriesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* The database schema.
|
||||
*
|
||||
* @var \Illuminate\Database\Schema\Builder
|
||||
*/
|
||||
protected $schema;
|
||||
|
||||
/**
|
||||
* Create a new migration instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->schema = Schema::connection($this->getConnection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$this->schema->create('telescope_entries', function (Blueprint $table) {
|
||||
$table->bigIncrements('sequence');
|
||||
$table->uuid('uuid');
|
||||
$table->uuid('batch_id');
|
||||
$table->string('family_hash')->nullable();
|
||||
$table->boolean('should_display_on_index')->default(true);
|
||||
$table->string('type', 20);
|
||||
$table->longText('content');
|
||||
$table->dateTime('created_at')->nullable();
|
||||
|
||||
$table->unique('uuid');
|
||||
$table->index('batch_id');
|
||||
$table->index('family_hash');
|
||||
$table->index('created_at');
|
||||
$table->index(['type', 'should_display_on_index']);
|
||||
});
|
||||
|
||||
$this->schema->create('telescope_entries_tags', function (Blueprint $table) {
|
||||
$table->uuid('entry_uuid');
|
||||
$table->string('tag');
|
||||
|
||||
$table->index(['entry_uuid', 'tag']);
|
||||
$table->index('tag');
|
||||
|
||||
$table->foreign('entry_uuid')
|
||||
->references('uuid')
|
||||
->on('telescope_entries')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
|
||||
$this->schema->create('telescope_monitoring', function (Blueprint $table) {
|
||||
$table->string('tag');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$this->schema->dropIfExists('telescope_entries_tags');
|
||||
$this->schema->dropIfExists('telescope_entries');
|
||||
$this->schema->dropIfExists('telescope_monitoring');
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
use App\Fee;
|
||||
use App\Member\Member;
|
||||
use App\Payment\Subscription;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use App\Payment\Subscription;
|
||||
use App\Fee;
|
||||
use App\Member\Member;
|
||||
|
||||
class CreateSubscriptionsRelationColumn extends Migration
|
||||
{
|
||||
|
@ -22,29 +22,10 @@ class CreateSubscriptionsRelationColumn extends Migration
|
|||
$table->foreignId('fee_id')->after('name')->constrained();
|
||||
});
|
||||
|
||||
foreach(Fee::get() as $fee) {
|
||||
Subscription::create([
|
||||
'amount' => 1000,
|
||||
'fee_id' => $fee->id,
|
||||
'name' => $fee->name,
|
||||
]);
|
||||
}
|
||||
|
||||
Schema::table('members', function (Blueprint $table) {
|
||||
$table->foreignId('subscription_id')->after('version')->nullable()->default(1)->constrained();
|
||||
});
|
||||
|
||||
Member::withoutEvents(function() {
|
||||
foreach (Member::get() as $member) {
|
||||
if (is_null($member->fee_id)) {
|
||||
$member->update(['subscription_id' => null]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$member->update(['subscription_id' => Subscription::firstWhere('fee_id', $member->fee_id)->id]);
|
||||
}
|
||||
});
|
||||
|
||||
Schema::table('members', function (Blueprint $table) {
|
||||
$table->dropForeign(['fee_id']);
|
||||
$table->dropColumn('fee_id');
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use App\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class UserSeeder extends Seeder
|
||||
|
@ -11,7 +12,7 @@ class UserSeeder extends Seeder
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
factory(App\User::class)->create([
|
||||
User::factory()->create([
|
||||
'email' => 'admin@example.com',
|
||||
'email_verified_at' => now(),
|
||||
'password' => Hash::make('admin')
|
||||
|
|
|
@ -7,7 +7,7 @@ class CreateGeneralSettings extends SettingsMigration
|
|||
|
||||
/**
|
||||
* @param string $mode
|
||||
* @return array<string, string|array>
|
||||
* @return array<string, array<int,string>|bool>
|
||||
*/
|
||||
public function defaults(string $mode): array
|
||||
{
|
||||
|
|
|
@ -37,9 +37,12 @@ class IndexTest extends TestCase
|
|||
]);
|
||||
$this->withoutExceptionHandling();
|
||||
$this->login();
|
||||
Member::factory()->defaults()->has(CourseMember::factory()->for(Course::factory()), 'courses')->create(['firstname' => '::firstname::']);
|
||||
|
||||
Member::factory()->defaults()->has(CourseMember::factory()->for(Course::factory()), 'courses')->create(['firstname' => '::firstname']);
|
||||
$this->get('/member')->assertInertia('member/Index', ['firstname' => '::firstname'], 'data.data.0');
|
||||
$response = $this->get('/member');
|
||||
|
||||
$this->assertComponent('member/Index', $response);
|
||||
$this->assertInertiaHas('::firstname::', $response, 'data.data.0.firstname');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ class GlobalSettingTest extends TestCase
|
|||
|
||||
$response = $this->get('/setting');
|
||||
|
||||
$response->assertInertiaComponent('setting/Index');
|
||||
$this->assertEquals(['bill'], $response->inertia('general.modules'));
|
||||
$this->assertComponent('setting/Index', $response);
|
||||
$this->assertEquals(['bill'], $this->inertia($response, 'general.modules'));
|
||||
}
|
||||
|
||||
public function testItGetsOptionsForModels(): void
|
||||
|
@ -33,7 +33,7 @@ class GlobalSettingTest extends TestCase
|
|||
|
||||
$response = $this->get('/setting');
|
||||
|
||||
$this->assertContains('bill', $response->inertia('options.modules'));
|
||||
$this->assertContains('bill', $this->inertia($response, 'options.modules'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,128 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Lib;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use PHPUnit\Framework\Assert as PHPUnit;
|
||||
|
||||
class InertiaMixin {
|
||||
|
||||
public function assertInertia() {
|
||||
return function($component, $props, $key = null) {
|
||||
PHPUnit::assertEquals($component, $this->viewData('page')['component']);
|
||||
|
||||
$this->assertInertiaHas($props, $key);
|
||||
|
||||
return $this;
|
||||
};
|
||||
}
|
||||
|
||||
public function assertInertiaComponent() {
|
||||
return function($component) {
|
||||
PHPUnit::assertEquals($component, $this->viewData('page')['component']);
|
||||
|
||||
return $this;
|
||||
};
|
||||
}
|
||||
|
||||
public function assertInertiaHasShared() {
|
||||
return function($bindings, $key = null) {
|
||||
$bindings = json_decode(json_encode($bindings), true);
|
||||
|
||||
$viewData = json_decode(json_encode(
|
||||
data_get($this->viewData('page'), $key)
|
||||
), true);
|
||||
|
||||
$this->assertDeepNest($bindings, $viewData);
|
||||
};
|
||||
}
|
||||
|
||||
public function assertInertiaHas() {
|
||||
return function($bindings, $key = null) {
|
||||
$bindings = json_decode(json_encode($bindings), true);
|
||||
|
||||
$viewData = json_decode(json_encode(
|
||||
data_get($this->viewData('page')['props'], $key)
|
||||
), true);
|
||||
|
||||
$bindings = is_array($bindings) ? $bindings : [$bindings];
|
||||
$viewData = is_array($viewData) ? $viewData : [$viewData];
|
||||
|
||||
$this->assertDeepNest($bindings, $viewData);
|
||||
};
|
||||
}
|
||||
|
||||
public function assertDeepNest() {
|
||||
return function($should, $is) {
|
||||
foreach ($should as $key => $value) {
|
||||
PHPUnit::assertArrayHasKey($key, $is);
|
||||
|
||||
if (is_array($value)) {
|
||||
$this->assertDeepNest($value, $is[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
PHPUnit::assertSame($value, $is[$key]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public function assertInertiaHasItem() {
|
||||
|
||||
return function($should, $nestedKey) {
|
||||
$is = data_get($this->viewData('page')['props'], $nestedKey);
|
||||
$is = collect(json_decode(json_encode($is), true));
|
||||
|
||||
$should = collect(json_decode(json_encode($should), true));
|
||||
|
||||
$has = $is->contains(function($isItem) use ($should) {
|
||||
return $this->isDeepEqual($should, Collection::wrap($isItem));
|
||||
});
|
||||
|
||||
PHPUnit::assertTrue($has, 'Failed asserting that inertia attribute '.$nestedKey.' has Data '.print_r($should, true));
|
||||
|
||||
return $this;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public function inertia() {
|
||||
return function($item) {
|
||||
return data_get($this->viewData('page')['props'], $item);
|
||||
};
|
||||
}
|
||||
|
||||
public function assertInertiaEquals() {
|
||||
return function($should, $nestedKey) {
|
||||
$is = data_get($this->viewData('page')['props'], $nestedKey);
|
||||
|
||||
PHPUnit::assertSame($should, $is);
|
||||
|
||||
return $this;
|
||||
};
|
||||
}
|
||||
|
||||
public function ddp() {
|
||||
return function ($value) {
|
||||
dd(data_get($this->viewData('page'), $value));
|
||||
};
|
||||
}
|
||||
|
||||
public function ddi() {
|
||||
return function ($value) {
|
||||
dd(data_get($this->viewData('page')['props'], $value));
|
||||
};
|
||||
}
|
||||
|
||||
public function isDeepEqual() {
|
||||
return function (Collection $subset, Collection $compare) {
|
||||
$subset = $subset->filter(fn($item) => !is_array($item));
|
||||
$compare = $compare->filter(fn($item) => !is_array($item));
|
||||
|
||||
return $subset->diffAssoc($compare)->isEmpty();
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Lib;
|
||||
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use PHPUnit\Framework\Assert as PHPUnit;
|
||||
|
||||
trait TestsInertia {
|
||||
|
||||
public function assertInertiaHas($value, TestResponse $response, ?string $key = null): void
|
||||
{
|
||||
$bindings = json_decode(json_encode($value), true);
|
||||
$viewData = json_decode(json_encode(
|
||||
data_get($response->viewData('page')['props'], $key)
|
||||
), true);
|
||||
$bindings = is_array($bindings) ? $bindings : [$bindings];
|
||||
$viewData = is_array($viewData) ? $viewData : [$viewData];
|
||||
$this->assertInertiaDeepNest($bindings, $viewData);
|
||||
}
|
||||
|
||||
public function assertComponent(string $component, TestResponse $response) {
|
||||
PHPUnit::assertEquals($component, $response->viewData('page')['component']);
|
||||
}
|
||||
|
||||
public function assertInertiaDeepNest($should, $is) {
|
||||
foreach ($should as $key => $value) {
|
||||
PHPUnit::assertArrayHasKey($key, $is);
|
||||
|
||||
if (is_array($value)) {
|
||||
$this->assertInertiaDeepNest($value, $is[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
PHPUnit::assertSame($value, $is[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
public function inertia(TestResponse $response, string $key) {
|
||||
return data_get($response->viewData('page')['props'], $key);
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ use App\Member\Member;
|
|||
use App\Setting\GeneralSettings;
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
use Tests\Lib\InertiaMixin;
|
||||
use Tests\Lib\TestsInertia;
|
||||
use Zoomyboy\LaravelNami\Backend\FakeBackend;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\NamiUser;
|
||||
|
@ -14,12 +14,7 @@ use Zoomyboy\LaravelNami\NamiUser;
|
|||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
use CreatesApplication;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
TestResponse::mixin(new InertiaMixin());
|
||||
}
|
||||
use TestsInertia;
|
||||
|
||||
public function fakeAuthUser() {
|
||||
app(FakeBackend::class)
|
||||
|
|
Loading…
Reference in New Issue