Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/test-assertions' into test-asser…
Browse files Browse the repository at this point in the history
…tions

# Conflicts:
#	src/LaravelConsoleValidatorServiceProvider.php
  • Loading branch information
PerryvanderMeer committed Aug 7, 2024
2 parents b64294d + 126dd90 commit 2c2f93c
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 60 deletions.
1 change: 0 additions & 1 deletion src/LaravelConsoleValidatorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);


namespace PerryvanderMeer\LaravelConsoleValidator;

use Illuminate\Support\ServiceProvider;
Expand Down
36 changes: 18 additions & 18 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php

declare(strict_types=1);

namespace PerryvanderMeer\LaravelConsoleValidator\Tests;

use Orchestra\Testbench\TestCase as Orchestra;
use PerryvanderMeer\LaravelConsoleValidator\LaravelConsoleValidatorServiceProvider;

class TestCase extends Orchestra
{
protected function getPackageProviders($app): array
{
return [
LaravelConsoleValidatorServiceProvider::class,
];
}
}
<?php

declare(strict_types=1);

namespace PerryvanderMeer\LaravelConsoleValidator\Tests;

use Orchestra\Testbench\TestCase as Orchestra;
use PerryvanderMeer\LaravelConsoleValidator\LaravelConsoleValidatorServiceProvider;

class TestCase extends Orchestra
{
protected function getPackageProviders($app) : array
{
return [
LaravelConsoleValidatorServiceProvider::class,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function handle() : int
{
if ($this->bool('foo') !== $this->boolean('foo'))
{
throw new LogicException();
throw new LogicException;
}

$type = gettype($this->bool('foo'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

test('that the command can cast a validated argument as string', function () : void
{
Artisan::registerCommand(new FakeCommandToCastASingleValidatedArgumentAsString());
Artisan::registerCommand(new FakeCommandToCastASingleValidatedArgumentAsString);

artisan(FakeCommandToCastASingleValidatedArgumentAsString::class, ['foo' => null])
->expectsOutput("Type: 'string'")
Expand All @@ -35,7 +35,7 @@

test('that the command can cast a validated argument as boolean', function () : void
{
Artisan::registerCommand(new FakeCommandToCastASingleValidatedArgumentAsBool());
Artisan::registerCommand(new FakeCommandToCastASingleValidatedArgumentAsBool);

artisan(FakeCommandToCastASingleValidatedArgumentAsBool::class, ['foo' => null])
->expectsOutput("Type: 'boolean'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

test('that the command can get a single validated argument', function () : void
{
Artisan::registerCommand(new FakeCommandToGetASingleValidatedArgument());
Artisan::registerCommand(new FakeCommandToGetASingleValidatedArgument);

artisan(FakeCommandToGetASingleValidatedArgument::class, ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'])
->expectsOutput("Foo: 'foo'")
Expand All @@ -23,7 +23,7 @@

test('that the command can get a validated nullable argument', function () : void
{
Artisan::registerCommand(new FakeCommandToGetASingleValidatedArgument());
Artisan::registerCommand(new FakeCommandToGetASingleValidatedArgument);

artisan(FakeCommandToGetASingleValidatedArgument::class, ['foo' => 'foo', 'bar' => null, 'baz' => 'baz'])
->expectsOutput("Foo: 'foo'")
Expand All @@ -36,15 +36,15 @@
$this->expectException(UnvalidatedArgumentException::class);
$this->expectExceptionMessage('The requested argument [foo] is not validated.');

Artisan::registerCommand(new FakeCommandToGetAnUnvalidatedArgument());
Artisan::registerCommand(new FakeCommandToGetAnUnvalidatedArgument);

artisan(FakeCommandToGetAnUnvalidatedArgument::class, ['foo' => 'foo'])
->assertSuccessful();
});

test('that the command can get all validated argument', function () : void
{
Artisan::registerCommand(new FakeCommandToGetAllValidatedArguments());
Artisan::registerCommand(new FakeCommandToGetAllValidatedArguments);

artisan(FakeCommandToGetAllValidatedArguments::class, ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'])
->expectsOutput('{"foo":"foo","bar":"bar"}')
Expand All @@ -53,7 +53,7 @@

test('that the command can collect all validated argument', function () : void
{
Artisan::registerCommand(new FakeCommandToCollectAllValidatedArguments());
Artisan::registerCommand(new FakeCommandToCollectAllValidatedArguments);

artisan(FakeCommandToCollectAllValidatedArguments::class, ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'])
->expectsOutput("Type: 'Illuminate\Support\Collection'")
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/FakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

test('that a normal command is working', function () : void
{
Artisan::registerCommand(new FakeCommandWithoutValidator());
Artisan::registerCommand(new FakeCommandWithoutValidator);

artisan(FakeCommandWithoutValidator::class)
->assertSuccessful();
});

test('that a command with the validator is working', function () : void
{
Artisan::registerCommand(new FakeCommandWithValidator());
Artisan::registerCommand(new FakeCommandWithValidator);

artisan(FakeCommandWithValidator::class)
->assertSuccessful();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

test('that the validator prepares the argument for validation', function () : void
{
Artisan::registerCommand(new FakeCommandWithArgumentPreparation());
Artisan::registerCommand(new FakeCommandWithArgumentPreparation);

artisan(FakeCommandWithArgumentPreparation::class, ['foo' => 'foo'])
->expectsOutput('foo-bar')
Expand All @@ -21,7 +21,7 @@

test('that the validator prepares the arguments for validation', function () : void
{
Artisan::registerCommand(new FakeCommandWithArgumentsPreparation());
Artisan::registerCommand(new FakeCommandWithArgumentsPreparation);

artisan(FakeCommandWithArgumentsPreparation::class, ['foo' => 'foo', 'bar' => 'bar'])
->expectsOutput('foo-bar')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

test('that the validator registers attributes from the attributes property', function () : void
{
Artisan::registerCommand(new FakeCommandWithAttributesProperty());
Artisan::registerCommand(new FakeCommandWithAttributesProperty);

artisan(FakeCommandWithAttributesProperty::class)
->assertSuccessful();

expect((new FakeCommandWithAttributesProperty())->getExtractedValidationAttributesForCommand())
expect((new FakeCommandWithAttributesProperty)->getExtractedValidationAttributesForCommand())
->toBeArray()
->toBe([
'foo' => 'bar',
Expand All @@ -26,12 +26,12 @@

test('that the validator registers attributes from the attributes method', function () : void
{
Artisan::registerCommand(new FakeCommandWithAttributesMethod());
Artisan::registerCommand(new FakeCommandWithAttributesMethod);

artisan(FakeCommandWithAttributesMethod::class)
->assertSuccessful();

expect((new FakeCommandWithAttributesMethod())->getExtractedValidationAttributesForCommand())
expect((new FakeCommandWithAttributesMethod)->getExtractedValidationAttributesForCommand())
->toBeArray()
->toEqual([
'baz' => 'bax',
Expand All @@ -41,12 +41,12 @@

test('that the validator registers attributes from the both the attributes property and the attributes method', function () : void
{
Artisan::registerCommand(new FakeCommandWithAttributesPropertyAndMethod());
Artisan::registerCommand(new FakeCommandWithAttributesPropertyAndMethod);

artisan(FakeCommandWithAttributesPropertyAndMethod::class)
->assertSuccessful();

expect((new FakeCommandWithAttributesPropertyAndMethod())->getExtractedValidationAttributesForCommand())
expect((new FakeCommandWithAttributesPropertyAndMethod)->getExtractedValidationAttributesForCommand())
->toBeArray()
->toEqual([
'foo' => 'bar',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

test('that the validator registers messages from the messages property', function () : void
{
Artisan::registerCommand(new FakeCommandWithMessagesProperty());
Artisan::registerCommand(new FakeCommandWithMessagesProperty);

artisan(FakeCommandWithMessagesProperty::class)
->assertSuccessful();

expect((new FakeCommandWithMessagesProperty())->getExtractedValidationMessagesForCommand())
expect((new FakeCommandWithMessagesProperty)->getExtractedValidationMessagesForCommand())
->toBeArray()
->toBe([
'foo' => 'bar',
Expand All @@ -26,12 +26,12 @@

test('that the validator registers messages from the messages method', function () : void
{
Artisan::registerCommand(new FakeCommandWithMessagesMethod());
Artisan::registerCommand(new FakeCommandWithMessagesMethod);

artisan(FakeCommandWithMessagesMethod::class)
->assertSuccessful();

expect((new FakeCommandWithMessagesMethod())->getExtractedValidationMessagesForCommand())
expect((new FakeCommandWithMessagesMethod)->getExtractedValidationMessagesForCommand())
->toBeArray()
->toEqual([
'baz' => 'bax',
Expand All @@ -41,12 +41,12 @@

test('that the validator registers messages from the both the messages property and the messages method', function () : void
{
Artisan::registerCommand(new FakeCommandWithMessagesPropertyAndMethod());
Artisan::registerCommand(new FakeCommandWithMessagesPropertyAndMethod);

artisan(FakeCommandWithMessagesPropertyAndMethod::class)
->assertSuccessful();

expect((new FakeCommandWithMessagesPropertyAndMethod())->getExtractedValidationMessagesForCommand())
expect((new FakeCommandWithMessagesPropertyAndMethod)->getExtractedValidationMessagesForCommand())
->toBeArray()
->toEqual([
'foo' => 'bar',
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/ResolveValidationLogic/RegisterValidatorRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

test('that the validator registers rules from the rules property', function () : void
{
Artisan::registerCommand(new FakeCommandWithRulesProperty());
Artisan::registerCommand(new FakeCommandWithRulesProperty);

artisan(FakeCommandWithRulesProperty::class)
->assertSuccessful();

expect((new FakeCommandWithRulesProperty())->getExtractedValidationRulesForCommand())
expect((new FakeCommandWithRulesProperty)->getExtractedValidationRulesForCommand())
->toBeArray()
->toBe([
'foo' => ['bar'],
Expand All @@ -28,12 +28,12 @@

test('that the validator registers rules from the rules method', function () : void
{
Artisan::registerCommand(new FakeCommandWithRulesMethod());
Artisan::registerCommand(new FakeCommandWithRulesMethod);

artisan(FakeCommandWithRulesMethod::class)
->assertSuccessful();

expect((new FakeCommandWithRulesMethod())->getExtractedValidationRulesForCommand())
expect((new FakeCommandWithRulesMethod)->getExtractedValidationRulesForCommand())
->toBeArray()
->toEqual([
'foo' => [Rule::file()],
Expand All @@ -44,12 +44,12 @@

test('that the validator registers rules from the both the rules property and the rules method', function () : void
{
Artisan::registerCommand(new FakeCommandWithRulesPropertyAndMethod());
Artisan::registerCommand(new FakeCommandWithRulesPropertyAndMethod);

artisan(FakeCommandWithRulesPropertyAndMethod::class)
->assertSuccessful();

expect((new FakeCommandWithRulesPropertyAndMethod())->getExtractedValidationRulesForCommand())
expect((new FakeCommandWithRulesPropertyAndMethod)->getExtractedValidationRulesForCommand())
->toBeArray()
->toEqual([
'foo' => ['bar', Rule::file()],
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Testing/AddAssertionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Illuminate\Support\Facades\Artisan;
use PerryvanderMeer\LaravelConsoleValidator\Tests\TestCommands\ValidatesArguments\FakeCommandWithRule;

use function Pest\Laravel\artisan;

test('that the assertFailedWithValidationError() assertion works', function () : void
{
Artisan::registerCommand(new FakeCommandWithRule());
Artisan::registerCommand(new FakeCommandWithRule);

artisan(FakeCommandWithRule::class, ['foo' => 'foo-bop'])
->assertSuccessful();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
Session::shouldReceive('put')->never();

Artisan::registerCommand(new FakeCommandToTestHandleMethod());
Artisan::registerCommand(new FakeCommandToTestHandleMethod);

artisan(FakeCommandToTestHandleMethod::class, ['foo' => 'foo'])
->assertExitCode(Command::INVALID)
Expand All @@ -24,7 +24,7 @@
{
Session::shouldReceive('put')->once();

Artisan::registerCommand(new FakeCommandToTestHandleMethod());
Artisan::registerCommand(new FakeCommandToTestHandleMethod);

artisan(FakeCommandToTestHandleMethod::class, ['foo' => 'foo-bar'])
->assertSuccessful();
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ValidatesArguments/ValidatorAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

test('that the validator supports custom attributes for an argument', function () : void
{
Artisan::registerCommand(new FakeCommandWithRulesAndAttributes());
Artisan::registerCommand(new FakeCommandWithRulesAndAttributes);

artisan(FakeCommandWithRulesAndAttributes::class, ['foo' => 'foo', 'bar' => 'bar'])
->expectsOutput('The first field must be at least 4 characters.')
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/ValidatesArguments/ValidatorMessagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

test('that the validator returns custom messages for a whole argument', function () : void
{
Artisan::registerCommand(new FakeCommandWithRulesAndMessages());
Artisan::registerCommand(new FakeCommandWithRulesAndMessages);

artisan(FakeCommandWithRulesAndMessages::class, ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'])
->expectsOutput('Whoo general message for foo argument..!')
Expand All @@ -23,7 +23,7 @@

test('that the validator returns custom messages for a specific rule', function () : void
{
Artisan::registerCommand(new FakeCommandWithRulesAndMessages());
Artisan::registerCommand(new FakeCommandWithRulesAndMessages);

artisan(FakeCommandWithRulesAndMessages::class, ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'])
->expectsOutput('Hmm the bar argument is very short..!')
Expand All @@ -35,7 +35,7 @@

test('that the validator returns default messages ', function () : void
{
Artisan::registerCommand(new FakeCommandWithRulesAndMessages());
Artisan::registerCommand(new FakeCommandWithRulesAndMessages);

artisan(FakeCommandWithRulesAndMessages::class, ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'])
->expectsOutput('The baz field must be at least 6 characters.')
Expand All @@ -48,7 +48,7 @@
{
config()->set('app.locale', 'nl');

Artisan::registerCommand(new FakeCommandWithRulesAndMessages());
Artisan::registerCommand(new FakeCommandWithRulesAndMessages);

Lang::addLines(
lines: [
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/ValidatesArguments/ValidatorRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

test('that the validator validates a single argument', function () : void
{
Artisan::registerCommand(new FakeCommandWithRule());
Artisan::registerCommand(new FakeCommandWithRule);

artisan(FakeCommandWithRule::class, ['foo' => 'foo'])
->expectsOutput('The foo field must be at least 4 characters.')
Expand All @@ -34,7 +34,7 @@

test('that the validator validates multiple arguments', function () : void
{
Artisan::registerCommand(new FakeCommandWithRules());
Artisan::registerCommand(new FakeCommandWithRules);

artisan(FakeCommandWithRules::class, ['foo' => 'foo', 'bar' => 'bar'])
->expectsOutput('The foo field must be at least 4 characters.')
Expand Down Expand Up @@ -62,7 +62,7 @@

test('that the validator performs the argument preparation before validating the arguments', function () : void
{
Artisan::registerCommand(new FakeCommandWithRulesAndArgumentPreparation());
Artisan::registerCommand(new FakeCommandWithRulesAndArgumentPreparation);

artisan(FakeCommandWithRulesAndArgumentPreparation::class, ['foo' => 'foo', 'bar' => 'bar'])
->expectsOutput('The foo field must be at least 7 characters.')
Expand Down

0 comments on commit 2c2f93c

Please sign in to comment.