Ad
How To Test That A Job Is Released After A Certain Time When Failing?
When I have a job like this
class CheckVideoStatusJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $video;
public function __construct(Video $video)
{
$this->video = $video;
}
public function handle(CheckStatusAction $action)
{
if (! $action->execute($this->video)) {
$this->release(60);
}
}
}
How can I test: when the job has failed it will be released back to the queue after (60) seconds?
Ad
Answer
In my opinion you rely on Laravels own tests to secure release method works and in a work environment not use time testing this. If you still want to, you just need to be sure that release is called. I would do a partial mock using Mockery.
This code creates a class that only mocks the release method and pass the video to the constructor.
$mock = \Mockery::mock(CheckVideoStatusJob::class, $video)->makePartial();
// expects release call, once, parameter should be 60 returns null
$mock->shouldReceive('release')->once()->with(60)->return(null);
// action should offcourse secure that execute returns false
$mock->handle($action);
For securing the tests use assertions with mockery use the mockery trait.
use MockeryPHPUnitIntegration;
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad