execute(static function (): string { Tag::factory()->createOne(['label' => 'Tx Committed Tag']); return 'success'; }); // THEN expect($result)->toBe('success') ->and(Tag::query()->where('label', 'Tx Committed Tag')->exists())->toBeTrue(); }); it('rolls back database writes when callback throws an exception', function (): void { // GIVEN $manager = new LaravelTransactionManager(); // WHEN $action = static fn (): mixed => $manager->execute(static function (): never { Tag::factory()->createOne(['label' => 'Tx Rolled Back Tag']); throw new \RuntimeException('Transaction failure'); }); // THEN expect($action)->toThrow(\RuntimeException::class, 'Transaction failure') ->and(Tag::query()->where('label', 'Tx Rolled Back Tag')->exists())->toBeFalse(); }); });