SeedsPermissions cache breaks some seeders in tests
The caching within getRole()
causes errors when linking newly created roles with permissions.
It appears that the static::$cachedRoles
isn't reset between tests (makes sense). I'm unsure if the solution is to cache purely within the seedsPermissions()
function or use Cache::remember()
.
Error info
SQLSTATE[23000]: Integrity constraint violation: 19 FOREIGN KEY constraint failed
(SQL: insert into "role_has_permissions" ("permission_id", "role_id") values (47, 8))
8
here is the ID of the newly created role.
It works fine with the caching removed.
Looks like the function finds the cached permission from the last test and attempts to use it even though the database has been refreshed for the next test.