›
›
›
  1. docs
  2. ›
  3. byrcsc/laravel-checklist
1.x
Browse documentationOpenClose

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Templates and versions
  • Items and sections
  • Checklist lifecycle
  • Answers and evidence
  • Conditional rules
  • Scoring
  • Recurring schedules
  • Audit history

Operations

  • Author a template
  • Run a checklist
  • Create a schedule
  • Customize notifications
  • Export and report
  • Verify audit history
  • Composing with sibling packages

Reference

  • Configuration
  • Builder API
  • Models and scopes
  • Events and notifications
  • Console commands
  • Enums and contracts
  • Testing
  • Troubleshooting

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Templates and versions
  • Items and sections
  • Checklist lifecycle
  • Answers and evidence
  • Conditional rules
  • Scoring
  • Recurring schedules
  • Audit history

Operations

  • Author a template
  • Run a checklist
  • Create a schedule
  • Customize notifications
  • Export and report
  • Verify audit history
  • Composing with sibling packages

Reference

  • Configuration
  • Builder API
  • Models and scopes
  • Events and notifications
  • Console commands
  • Enums and contracts
  • Testing
  • Troubleshooting

byrcsc/laravel-checklist · 1.x

Testing.

Test checklist behavior with Laravel fakes, package models, and explicit transition assertions.

Checklist tests use the real package models alongside Laravel's database, event, notification, and storage test tools. The package ships neither a facade nor a dedicated fake.

Build small templates in tests

use ByRcsc\LaravelChecklist\Authoring\TemplateBuilder;

$version = TemplateBuilder::make('Inspection')
    ->passFail('Brakes')->required()->critical()
    ->text('Notes')
    ->publish();

$checklist = $version->start();

Keep each test template focused on the behavior under test. Publishing is transactional, so failed authoring assertions do not leave partial rows.

Assert events after operations

use ByRcsc\LaravelChecklist\Events\ItemAnswered;
use ByRcsc\LaravelChecklist\Events\ItemFailed;
use Illuminate\Support\Facades\Event;

Event::fake();

$checklist->answer($item, 'fail');

Event::assertDispatched(ItemAnswered::class, 1);
Event::assertDispatched(ItemFailed::class, 1);

Events dispatch after commit. When testing an outer transaction, attach a real listener instead of Event::fake() if the assertion depends on commit timing.

Fake evidence storage

use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;

Storage::fake('local');

$evidence = $checklist->addEvidence(
    $response,
    UploadedFile::fake()->image('damage.jpg'),
    'photo',
);

Storage::disk('local')->assertExists($evidence->path);

Set checklist.evidence.disk in the test when faking another disk. Assert the row hash with hash('sha256', $contents) when file identity matters.

Fake shipped notifications

use ByRcsc\LaravelChecklist\Notifications\ChecklistAssignedNotification;
use Illuminate\Support\Facades\Notification;

Notification::fake();

$version->start(assignedTo: $driver);

Notification::assertSentTo(
    $driver,
    ChecklistAssignedNotification::class,
);

The recipient model needs Laravel's Notifiable trait. The default channels are mail and database.

Assert incomplete submission

use ByRcsc\LaravelChecklist\Exceptions\IncompleteChecklistException;

try {
    $checklist->submit();
    $this->fail('Submission should have been rejected.');
} catch (IncompleteChecklistException $exception) {
    expect($exception->unmet)
        ->toHaveCount(1)
        ->and($exception->unmet[0]->itemLabel)
        ->toBe('Brakes');
}

Assert stored status and score after a rejected submission. They should remain unchanged.

Verify export query behavior

Load exports through the supplied scope when strict lazy-loading is enabled:

$export = Checklist::query()
    ->withExportRelations()
    ->findOrFail($checklist->id)
    ->toExport();

What to read next

  • Events and notifications for assertion payloads.
  • Run a checklist for the execution sequence under test.
  • Troubleshooting for failures caused by storage, state, or configuration.
PreviousEnums and contractsNextTroubleshooting
View source

On this page

  1. Build small templates in tests
  2. Assert events after operations
  3. Fake evidence storage
  4. Fake shipped notifications
  5. Assert incomplete submission
  6. Verify export query behavior
  7. What to read next