Vasyanya's avatar

How to test job arguments?

How to test job arguments if Exception is thrown after job is dispatched. This test below returns green, but i found no way to test job arguments.

Code:

<?php

namespace Tests\Feature;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Tests\TestCase;

class SomeJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    public function handle() {}
}

class NothingTest extends TestCase
{
    /** @test */
    public function dispatch_test()
    {
        $this->expectException(\Exception::class);
        $this->expectsJobs(SomeJob::class);

        // job dispatched and Exception thrown afterwards
        dispatch(new SomeJob("arg"));
        throw new \Exception();
    }
}
0 likes
0 replies

Please or to participate in this conversation.