Answer the question
In order to leave comments, you need to log in
How to create a mock in laravel unit tests?
There is a common unit test
<?php
namespace Tests\Unit\Listeners;
use App\Events\ApplicationSubmittedEvent;
use App\Listeners\NotifyEmployerListener;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
class NotifyEmployerListenerTest extends TestCase
{
/**
* A basic unit test example.
*
* @return void
*/
public function test_handle()
{
$listener = new NotifyEmployerListener();
$eventMock = $this->mock(ApplicationSubmittedEvent::class, function (MockInterface $mock) {
$mock->employer = 'test evployer';
$mock->shouldReceive('notify')->once();
});
$listener->handle($eventMock);
}
}
Answer the question
In order to leave comments, you need to log in
You are deriving your test class from PHPUnit and are surprised it doesn't have Laravel methods.
PS
I wanted to test the listener separately with a unit test (check that the handle method is called and no one deleted it)Here it is reasonable to make three tests:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question