diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 19d6402..4efa537 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -16,7 +16,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.1' coverage: none - name: Install composer dependencies diff --git a/config/persona.php b/config/persona.php index df36aaf..4f13ddc 100644 --- a/config/persona.php +++ b/config/persona.php @@ -8,4 +8,6 @@ // 'permissions' => ['*'], // ], ], + + 'default_role' => null, ]; diff --git a/database/migrations/create_persona_table.php.stub b/database/migrations/create_persona_table.php.stub index 959b4ba..64c0746 100644 --- a/database/migrations/create_persona_table.php.stub +++ b/database/migrations/create_persona_table.php.stub @@ -14,7 +14,7 @@ return new class extends Migration public function up() { Schema::table('users', function (Blueprint $table) { - $table->string('role')->nullable(); + $table->string('role')->nullable()->default(config('persona.default_role')); }); } diff --git a/tests/RoleTest.php b/tests/RoleTest.php index 2f25e37..b56f71b 100644 --- a/tests/RoleTest.php +++ b/tests/RoleTest.php @@ -17,3 +17,18 @@ expect($user->hasPermission('non-existing-permission'))->toBe(false); }); + +test('a default role can be set', function () { + $user = UserWithRole::forceCreate([ + 'name' => 'Test User', + 'email' => 'test@example.com', + 'password' => 'test', + 'role' => 'cashier', + ]); + + expect($user->role)->toBe('cashier'); + expect($user->hasRole('cashier'))->toBe(true); + expect($user->hasRole('owner'))->toBe(false); + expect($user->name)->toBe('Test User'); + expect($user->email)->toBe('test@example.com'); +}); diff --git a/tests/TestCase.php b/tests/TestCase.php index 5d25ef4..d322f78 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -52,6 +52,8 @@ public function getEnvironmentSetUp($app) ], ], ]); + + config()->set('persona.default_role', 'cashier'); } protected function setUpDatabase()