PHP Classes

File: tests/Unit/Doctor/Rules/UnindexedSoftDeleteTest.php

Recommend this page to a friend!
  Packages of Alberto Arena   Laravel Truss   tests/Unit/Doctor/Rules/UnindexedSoftDeleteTest.php   Download  
File: tests/Unit/Doctor/Rules/UnindexedSoftDeleteTest.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Laravel Truss
View a diagram of a Laravel application models
Author: By
Last change:
Date: 9 days ago
Size: 1,298 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

use
AlbertoArena\Truss\Doctor\Rules\Index\UnindexedSoftDelete;
use
AlbertoArena\Truss\Tests\Support\SchemaBuilder;

it('flags a deleted_at column with no index', function () {
   
$snapshot = SchemaBuilder::make()
        ->
table('posts', fn ($t) => $t->id()->string('title')->softDeletes())
        ->
build();

   
expect(doctorCheck(new UnindexedSoftDelete, $snapshot))
        ->
toHaveFinding('TRUSS-IDX-005', table: 'posts', column: 'deleted_at');
});

it('is clean when deleted_at is indexed', function () {
   
$snapshot = SchemaBuilder::make()
        ->
table('posts', fn ($t) => $t->id()->softDeletes()->index('deleted_at'))
        ->
build();

   
expect(doctorCheck(new UnindexedSoftDelete, $snapshot))->toBeClean();
});

it('accepts deleted_at inside a composite index', function () {
   
$snapshot = SchemaBuilder::make()
        ->
table('posts', fn ($t) => $t->id()->string('status')->softDeletes()->index(['status', 'deleted_at']))
        ->
build();

   
expect(doctorCheck(new UnindexedSoftDelete, $snapshot))->toBeClean();
});

it('ignores tables without soft deletes', function () {
   
$snapshot = SchemaBuilder::make()->table('posts', fn ($t) => $t->id())->build();

   
expect(doctorCheck(new UnindexedSoftDelete, $snapshot))->toBeClean();
});