illegal offset type in tests
I have many of my tests fail with the same error, and not sure why.
As an example test that is failing, its complaining about the ->test line
Solution:Jump to solution
I Finally found it.
So basically where im creating the temp users, I have to cast the uuid as a string when creating
```php
$user->id = (string) Str::uuid();...
19 Replies
And the page its referencing
THese tests used to work, until I implemented the spatie perrmissions plugin
Make sure you are seeding the roles and permissions too.
I have this in my TestCase setup flow
Done a dd in the TestCase, I can see the role definitely exists, and returns true if I check the user having the role
And what’s in the policy?
Along the lines of this, but I've even tested by just returning true in every function, same outcome
Hm. Filament honors the policy and your policy is checking permissions not roles. But I would expect it to work with true.
I've just tried adding ->givePermissionTo() on the user, but still getting the same Illegal offset type error. Im just so confused
But even then, its Super Admin im adding, does that not cover all permissions?
Permissions and Roles are separate in Spatie's package
when you seed the roles you also have to seed the permissions and assign the permissions to the roles if you want to use both
Im not actually wiping the database currently during these tests, so those permissions do already exist in the db.
do you have a repo you can share?
Sadly its a work one, so NDA.
I can try mimic as much of this as possible to remove redacted information to share. What particularly would you be looking for?
i'm using pest, but i have these helpers:
then in my tests i use
loginAsUser(role: 'Pages', permission: 'page');
to login the user with the appropriate permissions and role. and it works.Ill try replicate and give it a go
try using
->can()
instead of ->checkPermissionTo()
. I think that might be an internal method. The docs say to use ->can
The checkPermissionTo() came with the generation command. Apologies, im also using the https://github.com/althinect/filament-spatie-roles-permissions repo
GitHub
GitHub - Althinect/filament-spatie-roles-permissions
Contribute to Althinect/filament-spatie-roles-permissions development by creating an account on GitHub.
ah, don't know anything about the package. sorry. might get better support if you ask the question directly on that channel. #althinect-spatie-roles-permissions
WIll do. Thank you
if it's something in the package then it's not a filament question. 🙂
Solution
I Finally found it.
So basically where im creating the temp users, I have to cast the uuid as a string when creating
Else it was detecting as a LazyLoadFromUuid or some named object