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.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay