DEV Community

Amir Haghi
Amir Haghi

Posted on

How to test task scheduling in Laravel

I want to say my own experience about how to test task scheduling in Laravel. There is a task scheduler in Laravel that you can write your task in a callback function and it is completely explained in the docs. When it comes to testing it is possible to work with some sort of time traveling but I'm not sure about that.

The way that I do is that I write my task in a command and as we know a command is a regular class of PHP and we can write tests for that to be sure that is working correctly. But for task scheduling, in order to be sure that the task will be run on the specific time intervals, we have to trust to the core task schedulers of servers maybe :)

So test your own task correct and test it and trust to on to run your task is every interval.

Tell your opinion please.

Top comments (0)