PHP Classes

File: tests/Feature/Commands/DoctorCommandTest.php

Recommend this page to a friend!
  Packages of Alberto Arena   Laravel Truss   tests/Feature/Commands/DoctorCommandTest.php   Download  
File: tests/Feature/Commands/DoctorCommandTest.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,771 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

use
Illuminate\Support\Facades\Schema;

beforeEach(function () {
   
// A clean table and one with a real, high-confidence problem: no primary key.
   
Schema::create('members', function ($table) {
       
$table->id();
       
$table->string('email')->unique();
    });
   
Schema::create('ledger', function ($table) {
       
$table->string('entry');
    });
});

it('reports the finding and exits 1 when a problem is at the fail level', function () {
   
$this->artisan('truss:doctor')
        ->
expectsOutputToContain('TRUSS-INT-001')
        ->
expectsOutputToContain('ledger')
        ->
assertExitCode(1);
});

it('exits 0 and reports a clean run with the none preset', function () {
   
$this->artisan('truss:doctor', ['--preset' => 'none'])
        ->
expectsOutputToContain('no findings')
        ->
assertExitCode(0);
});

it('never fails when --fail-on is never', function () {
   
$this->artisan('truss:doctor', ['--fail-on' => 'never'])->assertExitCode(0);
});

it('outputs json with --format=json', function () {
   
$this->artisan('truss:doctor', ['--format' => 'json', '--preset' => 'none'])
        ->
expectsOutputToContain('"findings"')
        ->
expectsOutputToContain('"summary"')
        ->
assertExitCode(0);
});

it('rejects an unknown format with exit code 2', function () {
   
$this->artisan('truss:doctor', ['--format' => 'nope'])->assertExitCode(2);
});

it('skips a category with --skip', function () {
   
$this->artisan('truss:doctor', ['--skip' => 'integrity', '--fail-on' => 'never'])
        ->
doesntExpectOutputToContain('TRUSS-INT-001')
        ->
assertExitCode(0);
});

it('is also available as truss:check', function () {
   
$this->artisan('truss:check', ['--preset' => 'none'])->assertExitCode(0);
});