A
A
Alexander2018-12-19 14:38:17
PHPUnit
Alexander, 2018-12-19 14:38:17

How to disable (mock?) dispatch() in a controller method in laravel unit tests?

Hello!
Can you please tell me how to mock the dispatch() helper in the laravel phpunit test of the controller method?
Here is the controller method I'm testing:

public function foo() {
        $data = [
            'content' => $content,
            'from' => date('Y-m-d H:i:s'),
            'to' => date('Y-m-d H:i:s'),
        ];
        $report = (new BlockedItemsReport($data))->onQueue('default');
        dispatch($report); <- Эту часть нужно как-то мокнуть.. Подскажите, как?
        return back();
}

Here is the test code:
public function testFoo()
    {
        $faker = Faker\Factory::create();
        $response = $this->call('POST', route('make.foo'), [
            'content' => $faker->text(200),
        ]);
        $response->assertRedirect('/');
    }

Those. you need to somehow wet the dispatch() helper..
Many thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom, 2018-12-20
@dark1112

https://laravel.com/docs/5.7/mocking#bus-fake

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question