›
byrcsc/laravel-checklist · 1.x
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.
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.
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.
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.
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.
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.
Load exports through the supplied scope when strict lazy-loading is enabled:
$export = Checklist::query()
->withExportRelations()
->findOrFail($checklist->id)
->toExport();