Closed dsge closed 7 years ago
I haven't tried to emit the JobProcessed
event manually.
But the incompatibility seems due to how Laravel handles "Job" internally.
When a "Job" is dispatched to queue, it wait for worker to pick it up.
The worker then pick up the "Job" as Illuminate\Queue\Jobs\[SyncJob|RedisJob|BeanstalkdJob...]
that implements Illuminate\Contracts\Queue\Job
,
and that Job
actually contains the "Job" you defined in user-space.
Although confusing, they are totally different things
Furthermore, the JobProcessing/JobProcessed/JobFailed/JobExceptionOccurred
events emitted by Laravel,
actually contains the [SyncJob/RedisJob/BeanstalkdJob...]
(that again contains your "Job"), not the "Job" you defined directly
But I am not sure if we can initiate instances of those Job
directly
Thank you for your response.
Turns out you were right, those are two separate things. I have also overcomplicated the problem. Since laravel's default phpunit.xml
sets the QUEUE_DRIVER
to sync
in tests I should have simply just dispatched my ConvertAudio job and let Laravel do it's thing.
This is what I did initally:
$job = new ConvertAudio($model, [
['format' => new \FFMpeg\Format\Audio\Mp3()]
]);
$job->ffmpeg = $ffmpegMock;
$status = \Imtigger\LaravelJobStatus\JobStatus::find($model->fresh()->last_job_status_id);
$this->assertEquals("queued", $status->status);
$job->handle();
event(new JobProcessed("foo", $job));
$this->assertEquals("finished", $status->fresh()->status);
But what I should have done is:
$job = new ConvertAudio($model, [
['format' => new \FFMpeg\Format\Audio\Mp3()]
]);
$job->ffmpeg = $ffmpegMock;
$status = \Imtigger\LaravelJobStatus\JobStatus::find($model->fresh()->last_job_status_id);
$this->assertEquals("queued", $status->status);
dispatch($job);
$this->assertEquals("finished", $status->fresh()->status);
I should have never tried to call ->handle()
on my job manually. Now this works as expected and it passes the test.
I am closing this issue since this is not related to this library.
Anyway, thank you for sharing your findings :)
I am trying to write a test for my Laravel Job which uses this library. The thought process is this:
new ConvertAudio()
thestatus
in thejob_statuses
table will bequeued
Illuminate\Queue\Events\JobProcessed
) fires when you try to test a job like thisJobProcessed
eventJobStatus
correctly after it's filledI am running into a little incompatibility after firing the
JobProcessed
event.Here is my code and the exception:
If I try to implement
Illuminate\Contracts\Queue\Job
(by extendingIlluminate\Queue\Jobs\Job
) I get this:Am I missing something?
Edit: I am using