mardi 27 janvier 2015

Mocking a variable/attribute for tests

I'm writing some phpunit tests for my laravel app. It's been fine up until now. I successfully mocked many facades or dependency injection based objects.


Now I'm working on API. I store the api user entity in the base controller class attribute and then access it when needed (since it's not actually a logged in user anymore).


The problem is that I want to mock this attribute when testing. How can I do that?


Is there a way to mock a controller attribute or define a shouldReceive(method)->andReturn($something) on controller method?


Thank you


Aucun commentaire:

Enregistrer un commentaire