I am beginning to write tests using Laravel 4.2, PHPUnit, and Mockery.
How can I assert that a Mock Facade was called/run by the Controller that I am testing?
For example, I've got the following Mockery for Queue
. My controller doesn't return anything that has to do with the Queue::push()
, so is there a way I can assert that it triggered Queue::push()
?
Queue::shouldReceive('push')->once();
Queue::shouldReceive('connected')->once();
If I comment out the Queue::push()
in my controller, the Queue::shouldReceive
throws an exception:
Mockery\Exception\InvalidCountException: Method push() from Mockery_0_Illuminate_Queue_QueueManager should be called exactly 1 times but called 0 times.
Is the only way to assert that the Mock Facade ran is to do something like the following?
$queuepushran = false;
try {
Queue::shouldReceive('push')->once();
Queue::shouldReceive('connected')->once();
$queuepushran = true;
} catch (\Mockery\Exception\InvalidCountException $e) {
//Queue threw an exception
$queuepushran = false;
}
$this->assertTrue($queuepushran);