Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Health Laravel Package

spatie/laravel-health

Monitor your Laravel app’s health by registering checks (disk space, etc.) with warning/fail thresholds. Get notified via mail or Slack when checks degrade, and extend with custom checks for proactive alerting.

View on GitHub
Deep Wiki
Context7

title: Testing weight: 5

You may wish to test that your checks are handled correctly, without needing to satisfy the requirements of the check itself. The package provides the ability to fake the results of checks.

Basic usage

The Health Facade has a fake method that allows you to fake the results of a check. Let's use it to make the DatabaseCheck fail in a test:

it('has an error if the database is not available', function () {
  Health::fake([
    DatabaseCheck::class => new Result(Status::failed())
  ]);

  $this->get('/health')->assertStatus(503);
});

Even if the database is available, the health endpoint will fail thanks to our fake. You may fake as many checks as you'd like in the array passed to the fake method.

Advanced usage

There may be occasions where you need to override the shouldRun method in a fake. To accomplish this, you may call FakeCheck::result and pass a boolean indicating whether the check should run:

it('has an error if the database is not available', function () {
  Health::fake([
    DatabaseCheck::class => FakeCheck::result(
        new Result(Status::failed()),
        true // Run this check, even if `shouldRun` returns false in the check itself
    )
  ]);

  $this->get('/health')->assertStatus(503);
});

On rare occasions, you may have multiple instances of the same check, and wish to return different results for each. The package allows you to provide a closure, which will receive the instance of the check as an argument:

it('has an error if the database is not available', function () {
  Health::fake([
    DatabaseCheck::class => fn($check) => $check->getName() === 'Users DB' 
        ? new Result(Status::ok())
        : new Result(Status::failed())
  ]);

  $this->get('/health')->assertStatus(503);
});
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport