Reputation: 1520
Every time I try to test a class that has a repository in it I came with the same question:
If an Eloquent class "hydrates" the protected array relations attribute after performing a query, I could in theory populate this attribute with a mock Collection/Resultset so when in my test I say something like $user->profiles
(attribute without parenthesis) I could retrieve my mock data and test the model easily.
My question is: is there a way to make Mockery call the __call
method without issuing an "attribute not found" error message?
So far, the only way I've achieved to do this is by applying the attribute directly to the mock object. The problem with this approach is that this way I can't assert if the data was read from the repository
If you need an example I can update the question, but I think I've been quite explicit ;)
Best regards
Upvotes: 2
Views: 1531
Reputation: 3326
I'm new to all of this, but I've read you can use AspectMock to test an Eloquent model. Jeffery Way has a video explaining how it's done. Here is the original post explaining AspectMock at Codeception.
Upvotes: 1