mardi 9 avril 2019

Laravel Mock Policy during Testing

I would like to verify, that a Policy method is called at the correct time with the correct parameters.

In my controller I call $this->authorize('edit', $entry) and would like to ensure the edit method in my entryPolicy.class is called.

I have tried Mocking the Gate Facade, which fails because I am not logged in during testing. (Unit test, no Feature test)

I have tried Mocking the Policy using Mockery, but since the Mock is ignored since the Policy is already instantiated and registered when the test runs. (or so i presume)

Last I tried registering the mocked Policy using the Gate Facade, which didn't work either

Ideally, the working code should look something like this:

 $uut=\Mockery::mock(entryPolicy::class);
 $uut->shouldReceive('update')->andReturn();
 $controler->update($request, $entry);

Any help is greatly appreciated

Aucun commentaire:

Enregistrer un commentaire