Contributing

This page explains how to set up laravel-schedule-monitor for development, run its test suite, follow its code style, and report security issues. The general contribution guidelines are Spatie's shared CONTRIBUTING guide.

Development Setup

git clone https://github.com/spatie/laravel-schedule-monitor.git
cd laravel-schedule-monitor
composer install

The package is developed against Orchestra Testbench, so no Laravel application is needed.

Running the Tests

composer test

This runs Pest (vendor/bin/pest). A coverage report can be generated with:

composer test-coverage

which runs PHPUnit with an HTML coverage report in coverage/.

How the Test Suite Is Set Up

Knowing the test infrastructure helps when writing new tests:

Piece Purpose
tests/TestCase.php Boots the package with an in-memory SQLite database, runs the migration stub, sets a fake Oh Dear token and monitor id 1, and replaces the Termwind output with a buffer.
tests/TestClasses/TestKernel.php A console kernel whose schedule is built from closures registered with TestKernel::registerScheduledTasks() or replaceScheduledTasks().
tests/TestClasses/FakeOhDear.php Replaces the Oh Dear API client; records synced and created cron checks and generates ping URLs on https://ping.ohdear.app (or endpoint_url).
tests/stubs/artisan An artisan file copied into the Testbench app so that scheduled commands can actually run through schedule:run.
useFakeUuids() Helper in tests/Pest.php that makes Str::uuid() return test-uuid-1, test-uuid-2, ...
spatie/test-time Freezes and advances time for the late-detection tests.

A typical test registers a schedule, runs the sync and the scheduler, and asserts on the database:

it('records a finished run', function () {
    TestKernel::registerScheduledTasks(function (Schedule $schedule) {
        $schedule->call(fn () => 1 + 1)->everyMinute()->monitorName('dummy-task');
    });

    $this->artisan(SyncCommand::class)->assertExitCode(0);
    $this->artisan('schedule:run')->assertExitCode(0);

    expect(MonitoredScheduledTask::findByName('dummy-task')->logItems->pluck('type')->all())
        ->toBe(['finished', 'starting']);
});

Continuous Integration

The run-tests GitHub Actions workflow runs the suite on Ubuntu for PHP 8.2 to 8.6, Laravel 12 and 13 (Laravel 13 is not tested on PHP 8.2), with both prefer-lowest and prefer-stable dependencies. Another workflow fixes code style with PHP CS Fixer, and one updates the changelog on release.

Code Style

composer format

runs php-cs-fixer fix --allow-risky=yes with the rules in .php_cs.dist.php.

Security

If you find a security problem, mail [email protected] instead of opening an issue.

Credits and License

The package was created by Freek Van der Herten at Spatie, with many contributors. It is open source under the MIT license. Spatie asks users who like their packages to send a postcard or to buy one of their paid products.

See Also