Skip to content

Commit

Permalink
fix: Remove gender migration and add Enum Type
Browse files Browse the repository at this point in the history
  • Loading branch information
mckenziearts committed Aug 17, 2024
1 parent 047181e commit c988af6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 59 deletions.
8 changes: 3 additions & 5 deletions packages/admin/src/Components/Form/GenderField.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@

use Filament\Forms\Components\Component;
use Filament\Forms\Components\Select;
use Shopper\Core\Enum\GenderType;

final class GenderField
{
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down

This file was deleted.

29 changes: 29 additions & 0 deletions packages/core/src/Enum/GenderType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Shopper\Core\Enum;

use Filament\Support\Contracts\HasLabel;
use Shopper\Core\Traits\HasEnumStaticMethods;

/**
* @method static string Male()
* @method static string Female()
*/
enum GenderType: string implements HasLabel
{
use HasEnumStaticMethods;

case Male = 'male';

case Female = 'female';

public function getLabel(): ?string
{
return match ($this) {
self::Male => __('shopper::words.male'),
self::Female => __('shopper::words.female'),
};
}
}
27 changes: 0 additions & 27 deletions tests/database/factories/UserFactory.php

This file was deleted.

13 changes: 8 additions & 5 deletions tests/src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 [
Expand Down Expand Up @@ -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'));
Expand Down

0 comments on commit c988af6

Please sign in to comment.