PHP Classes

File: tests/Feature/Doctor/SchemaBuilderContractTest.php

Recommend this page to a friend!
  Packages of Alberto Arena   Laravel Truss   tests/Feature/Doctor/SchemaBuilderContractTest.php   Download  
File: tests/Feature/Doctor/SchemaBuilderContractTest.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: 8 days ago
Size: 1,027 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

use
AlbertoArena\Truss\Introspection\SnapshotBuilder;
use
AlbertoArena\Truss\Tests\Support\SchemaBuilder;

beforeEach(function () {
    (require
__DIR__.'/../../Fixtures/migrations/0001_01_01_000000_create_fixture_tables.php')->up();
});

// The fixture SchemaBuilder must expose the same array shape real introspection
// produces, or rules unit-tested against it would drift from the production
// snapshot. This pins the table and column shape; index/foreign-key shape is
// added here as SchemaBuilder grows methods for them.
it('produces the same table and column shape as real introspection', function () {
   
$real = collect((new SnapshotBuilder)->build('testing')['tables'])->firstWhere('name', 'users');

   
$built = SchemaBuilder::make()
        ->
table('users', fn ($t) => $t->id()->string('email'))
        ->
build()['tables'][0];

   
expect(array_keys($built))->toBe(array_keys($real))
        ->
and(array_keys($built['columns'][0]))->toBe(array_keys($real['columns'][0]));
});