77use BinaryCats \LaravelRbac \Tests \Fixtures \Abilities \FooAbility ;
88use BinaryCats \LaravelRbac \Tests \TestCase ;
99use PHPUnit \Framework \Attributes \Test ;
10- use Spatie \Permission \Exceptions \PermissionDoesNotExist ;
1110
1211class SyncDefinedRoleTest extends TestCase
1312{
@@ -29,13 +28,29 @@ public function it_will_defer_syncing_defined_role_to_artisan(): void
2928 }
3029
3130 #[Test]
32- public function it_will_throw_an_exception_on_missing_permission (): void
31+ public function it_will_defer_syncing_defined_role_to_artisan_with_custom_guard (): void
3332 {
34- $ this -> expectException (PermissionDoesNotExist::class );
35- $ this -> expectExceptionMessage ( ' There is no permission named `bar` for guard `web` ' );
33+ StorePermission:: run ( ' bar ' , ' admin ' );
34+ StorePermission:: run (FooAbility::One, ' admin ' );
3635
37- SyncDefinedRole::run ('foo role ' , 'web ' , [
36+ SyncDefinedRole::run ('foo role ' , 'admin ' , [
3837 'bar ' ,
38+ FooAbility::One,
39+ 'this-permission-is-new-and-will-be-created ' ,
3940 ]);
41+
42+ $ this ->assertDatabaseHas (config ('permission.table_names.roles ' ), [
43+ 'name ' => 'foo role ' ,
44+ 'guard_name ' => 'admin ' ,
45+ ]);
46+
47+ $ role = app (config ('permission.models.role ' ))->where ([
48+ 'name ' => 'foo role ' ,
49+ 'guard_name ' => 'admin ' ,
50+ ])->firstOrFail ();
51+
52+ $ this ->assertTrue ($ role ->hasPermissionTo ('bar ' , 'admin ' ));
53+ $ this ->assertTrue ($ role ->hasPermissionTo (FooAbility::One, 'admin ' ));
54+ $ this ->assertTrue ($ role ->hasPermissionTo ('this-permission-is-new-and-will-be-created ' , 'admin ' ));
4055 }
4156}
0 commit comments