Testing tenant-aware resources in v4
What I am trying to do:
I'm trying to test the creation of a tenant-aware resource. I've just updated my application from version 3 following the upgrade guide.
The tests were working fine before the update, but now I'm getting an error related to a missing tenant ID in insert queries.
What I did:
I've read the new information about multi-tenancy (https://filamentphp.com/docs/4.x/users/tenancy#tenancy-security). I now understand that there is a middleware that automatically manages queries, but, since I'm coming from version 3, my models are manually managed to the tenant.
This shouldn't be a problem, because I've checked the code and seen that if the scope is already applied, nothing should happen. I've got no issues with browser requests, though, so I think there is probably something missing or wrong in the instructions. My issue/the error: Code:
This shouldn't be a problem, because I've checked the code and seen that if the scope is already applied, nothing should happen. I've got no issues with browser requests, though, so I think there is probably something missing or wrong in the instructions. My issue/the error: Code:
2 Replies
I forgot to mention that I've overridden the
setUp method of the TestCase class to set the tenant before every test
If you are not using Filaments build-in logic, how are you setting the current tenant id for new models?