Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #134

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions _ide_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/** @noinspection PhpUnusedAliasInspection */

namespace Illuminate\Testing {

/**
* @see \Spectator\Assertions
*
Expand All @@ -25,7 +24,6 @@ class TestResponse
}

namespace Illuminate\Foundation\Testing {

/**
* @see \Spectator\Assertions
*
Expand Down
4 changes: 4 additions & 0 deletions src/Support/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ class Format
// https://joshtronic.com/2013/09/02/how-to-use-colors-in-command-line-output/

const TEXT_GREEN = '0;32';

const TEXT_RED = '0;31';

const TEXT_WHITE = '1;37';

const TEXT_LIGHT_GREY = '0;37';

const TEXT_DARK_GREY = '1;30';

const STYLE_ITALIC = '3';
Expand Down
24 changes: 24 additions & 0 deletions src/Validation/RequestValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ protected function validateParameters()
}
}

/**
* @param mixed $parameter
* @param string|null $type
* @return mixed
*/
private function castParameter($parameter, ?string $type)
{
if ($type === null) {
return $parameter;
}

if ($type === 'integer' && filter_var($parameter, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE) !== null) {
return (int) $parameter;
} elseif ($type === 'number' && filter_var($parameter, FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE) !== null) {
return (float) $parameter;
} elseif ($type === 'boolean' && filter_var($parameter, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null) {
return filter_var($parameter, FILTER_VALIDATE_BOOLEAN);
} elseif ($type === 'string') {
return (string) $parameter;
}

return $parameter;
}

/**
* @throws RequestValidationException|SchemaValidationException
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/RequestValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,9 @@ public function test_handles_query_parameters_int(): void
return [];
})->middleware(Middleware::class);

$this->getJson('/users-by-id/foo')
->assertInvalidRequest();

$this->getJson('/users-by-id/1')
->assertValidRequest();
}
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
abstract class TestCase extends Orchestra
{
const NULLABLE_MISSING = 0;

const NULLABLE_EMPTY_STRING = 1;

const NULLABLE_VALID = 2;

const NULLABLE_INVALID = 3;

const NULLABLE_NULL = 4;

protected function getEnvironmentSetUp($app)
Expand Down