From c988af6c214e7b9abe9ad36dcf495c93edd9818e Mon Sep 17 00:00:00 2001 From: Arthur Monney Date: Sat, 17 Aug 2024 12:52:34 +0200 Subject: [PATCH] fix: Remove gender migration and add Enum Type --- .../admin/src/Components/Form/GenderField.php | 8 ++--- ...9_05_03_000001_create_customer_columns.php | 7 ++--- ...1_update_gender_columns_on_users_table.php | 17 ----------- packages/core/src/Enum/GenderType.php | 29 +++++++++++++++++++ tests/database/factories/UserFactory.php | 27 ----------------- tests/src/TestCase.php | 13 +++++---- 6 files changed, 42 insertions(+), 59 deletions(-) delete mode 100755 packages/core/database/migrations/2022_06_14_224741_update_gender_columns_on_users_table.php create mode 100644 packages/core/src/Enum/GenderType.php delete mode 100755 tests/database/factories/UserFactory.php diff --git a/packages/admin/src/Components/Form/GenderField.php b/packages/admin/src/Components/Form/GenderField.php index 04249ab79..cb2bc16ed 100755 --- a/packages/admin/src/Components/Form/GenderField.php +++ b/packages/admin/src/Components/Form/GenderField.php @@ -6,6 +6,7 @@ use Filament\Forms\Components\Component; use Filament\Forms\Components\Select; +use Shopper\Core\Enum\GenderType; final class GenderField { @@ -13,11 +14,8 @@ public static function make(): Component { return Select::make('gender') ->label(__('shopper::forms.label.gender')) - ->options([ - 'male' => __('shopper::words.male'), - 'female' => __('shopper::words.female'), - ]) - ->default('male') + ->options(GenderType::class) + ->default(GenderType::Male()) ->native(false); } } diff --git a/packages/core/database/migrations/2019_05_03_000001_create_customer_columns.php b/packages/core/database/migrations/2019_05_03_000001_create_customer_columns.php index 0892ba129..1886215b1 100755 --- a/packages/core/database/migrations/2019_05_03_000001_create_customer_columns.php +++ b/packages/core/database/migrations/2019_05_03_000001_create_customer_columns.php @@ -4,6 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; +use Shopper\Core\Enum\GenderType; use Shopper\Core\Helpers\Migration; return new class extends Migration @@ -17,7 +18,7 @@ public function up(): void $table->after('id', function (Blueprint $table): void { $table->string('first_name')->nullable(); $table->string('last_name'); - $table->string('gender')->default('male'); + $table->string('gender')->default(GenderType::Male()); $table->string('phone_number')->nullable(); $table->date('birth_date')->nullable(); $table->string('avatar_type')->default('avatar_ui'); @@ -45,10 +46,6 @@ public function down(): void 'opt_in', 'last_login_at', 'last_login_ip', - 'stripe_id', - 'card_brand', - 'card_last_four', - 'trial_ends_at', ]); $table->string('name'); diff --git a/packages/core/database/migrations/2022_06_14_224741_update_gender_columns_on_users_table.php b/packages/core/database/migrations/2022_06_14_224741_update_gender_columns_on_users_table.php deleted file mode 100755 index 222d4081e..000000000 --- a/packages/core/database/migrations/2022_06_14_224741_update_gender_columns_on_users_table.php +++ /dev/null @@ -1,17 +0,0 @@ -string('gender')->nullable()->default('male')->change(); - }); - } -}; diff --git a/packages/core/src/Enum/GenderType.php b/packages/core/src/Enum/GenderType.php new file mode 100644 index 000000000..5aedab4b7 --- /dev/null +++ b/packages/core/src/Enum/GenderType.php @@ -0,0 +1,29 @@ + __('shopper::words.male'), + self::Female => __('shopper::words.female'), + }; + } +} diff --git a/tests/database/factories/UserFactory.php b/tests/database/factories/UserFactory.php deleted file mode 100755 index 75af86b69..000000000 --- a/tests/database/factories/UserFactory.php +++ /dev/null @@ -1,27 +0,0 @@ - $this->faker->firstName(), - 'last_name' => $this->faker->lastName(), - 'email' => $this->faker->unique()->safeEmail(), - 'email_verified_at' => now(), - 'gender' => 'male', - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password - 'remember_token' => Str::random(10), - ]; - } -} diff --git a/tests/src/TestCase.php b/tests/src/TestCase.php index 9e53ae17c..06074ceb3 100755 --- a/tests/src/TestCase.php +++ b/tests/src/TestCase.php @@ -11,6 +11,7 @@ use Filament\Notifications\NotificationsServiceProvider; use Filament\Support\SupportServiceProvider; use Filament\Tables\TablesServiceProvider; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase; use Livewire\LivewireServiceProvider; use Mckenziearts\BladeUntitledUIIcons\BladeUntitledUIIconsServiceProvider; @@ -35,6 +36,13 @@ abstract class TestCase extends BaseTestCase protected string $seeder = ShopperSeeder::class; + protected function setUp(): void + { + parent::setUp(); + + $this->loadLaravelMigrations(); + } + protected function getPackageProviders($app): array { return [ @@ -62,11 +70,6 @@ protected function getEnvironmentSetUp($app): void $app['config']->set('auth.providers.users.model', User::class); } - protected function defineDatabaseMigrations(): void - { - $this->loadLaravelMigrations(); - } - protected function asAdmin(): TestCase { return $this->actingAs($this->makeAdminUser(), config('shopper.auth.guard'));