Skip to content

Commit

Permalink
Fix Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thettler committed May 7, 2023
1 parent 6f49954 commit 6eb1c22
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
7 changes: 5 additions & 2 deletions tests/ConsoleInputAutoAskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use Illuminate\Console\Application as Artisan;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\App;
use Illuminate\Translation\Translator;
use Thettler\LaravelConsoleToolkit\Attributes\Argument;
use Thettler\LaravelConsoleToolkit\Attributes\Option;
use Thettler\LaravelConsoleToolkit\Concerns\UsesConsoleToolkit;
Expand Down Expand Up @@ -143,11 +145,12 @@ public function handle()
};

Artisan::starting(fn (Artisan $artisan) => $artisan->add($command));
$translator = App::make(Translator::class);

\Pest\Laravel\artisan('validate LongerThan5 --shortOption=alsoLonger')
->expectsOutput('The short argument must not be greater than 5 characters.')
->expectsOutput($translator->get('validation.max.string', ['attribute' => 'short argument', 'max' => 5]))
->expectsQuestion('Please enter "shortArgument"', 'short')
->expectsOutput('The short option must not be greater than 5 characters.')
->expectsOutput($translator->get('validation.max.string', ['attribute' => 'short option', 'max' => 5]))
->expectsQuestion('Please enter "shortOption"', 'small')
->expectsOutput('short small')
->assertSuccessful();
Expand Down
32 changes: 18 additions & 14 deletions tests/ConsoleInputValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use Illuminate\Console\Application as Artisan;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\App;
use Illuminate\Translation\Translator;
use Thettler\LaravelConsoleToolkit\Attributes\Argument;
use Thettler\LaravelConsoleToolkit\Attributes\Option;
use Thettler\LaravelConsoleToolkit\Concerns\UsesConsoleToolkit;
Expand Down Expand Up @@ -30,15 +32,17 @@

public function handle()
{
$this->line($this->shortArgument . ' ' . $this->shortOption);
$this->line($this->shortArgument.' '.$this->shortOption);
}
};

Artisan::starting(fn (Artisan $artisan) => $artisan->add($command));
Artisan::starting(fn(Artisan $artisan) => $artisan->add($command));

$translator = App::make(Translator::class);

\Pest\Laravel\artisan('validate LongerThan5 --shortOption=alsoLonger')
->expectsOutput('The short argument must not be greater than 5 characters.')
->expectsOutput('The short option must not be greater than 5 characters.')
->expectsOutput($translator->get('validation.max.string', ['attribute' => 'short argument', 'max' => 5]))
->expectsOutput($translator->get('validation.max.string', ['attribute' => 'short option', 'max' => 5]))
->doesntExpectOutput('LongerThan5 alsoLonger')
->assertFailed();
});
Expand All @@ -59,23 +63,23 @@ public function handle()

public function handle()
{
$this->line($this->A->name . ' ' . $this->O->value);
$this->line($this->A->name.' '.$this->O->value);
}
};

Artisan::starting(fn (Artisan $artisan) => $artisan->add($command));
Artisan::starting(fn(Artisan $artisan) => $artisan->add($command));

\Pest\Laravel\artisan('validate notValid --O=notValid')
->expectsOutput('The selected a is invalid.')
->expectsOutput('Possible values for: A.')
->expectsOutput(' - ' . Enum::A->name)
->expectsOutput(' - ' . Enum::B->name)
->expectsOutput(' - ' . Enum::C->name)
->expectsOutput(' - '.Enum::A->name)
->expectsOutput(' - '.Enum::B->name)
->expectsOutput(' - '.Enum::C->name)
->expectsOutput('The selected o is invalid.')
->expectsOutput('Possible values for: O.')
->expectsOutput(' - ' . StringEnum::A->value)
->expectsOutput(' - ' . StringEnum::B->value)
->expectsOutput(' - ' . StringEnum::C->value)
->expectsOutput(' - '.StringEnum::A->value)
->expectsOutput(' - '.StringEnum::B->value)
->expectsOutput(' - '.StringEnum::C->value)
->assertFailed();
});

Expand Down Expand Up @@ -105,11 +109,11 @@ public function handle()

public function handle()
{
$this->line($this->shortArgument . ' ' . $this->shortOption);
$this->line($this->shortArgument.' '.$this->shortOption);
}
};

Artisan::starting(fn (Artisan $artisan) => $artisan->add($command));
Artisan::starting(fn(Artisan $artisan) => $artisan->add($command));

\Pest\Laravel\artisan('validate LongerThan5 --shortOption=alsoLonger')
->expectsOutput('This argument short argument is to long for you boy.')
Expand Down

0 comments on commit 6eb1c22

Please sign in to comment.