PHP Classes

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

Recommend this page to a friend!
  Packages of Alberto Arena   Laravel Truss   tests/Unit/Doctor/Rules/RedundantPrefixIndexTest.php   Download  
File: tests/Unit/Doctor/Rules/RedundantPrefixIndexTest.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,307 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

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

it('flags a non-unique index that is a left prefix of another', function () {
   
$snapshot = SchemaBuilder::make()
        ->
table('events', fn ($t) => $t->id()->string('a')->string('b')
            ->
index('a', 'events_a_index')
            ->
index(['a', 'b'], 'events_a_b_index'))
        ->
build();

   
expect(doctorCheck(new RedundantPrefixIndex, $snapshot))
        ->
toHaveFinding('TRUSS-IDX-003', table: 'events');
});

it('keeps a unique prefix index, which enforces a constraint the composite does not', function () {
   
$snapshot = SchemaBuilder::make()
        ->
table('events', fn ($t) => $t->id()->string('a')->string('b')
            ->
unique('a', 'events_a_unique')
            ->
index(['a', 'b'], 'events_a_b_index'))
        ->
build();

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

it('is clean when no index is a prefix of another', function () {
   
$snapshot = SchemaBuilder::make()
        ->
table('events', fn ($t) => $t->id()->string('a')->string('b')
            ->
index(['a', 'b'])->index('b'))
        ->
build();

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