Skip to content

Commit

Permalink
Added validation for the new config field.
Browse files Browse the repository at this point in the history
  • Loading branch information
ash-jc-allen committed Jul 2, 2024
1 parent 7c3c676 commit d95b881
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Classes/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function validateConfig(): bool
Rule::make('enforce_https')->rules(['required', 'boolean']),
Rule::make('forward_query_params')->rules(['required', 'boolean']),
Rule::make('default_url')->rules(['nullable', 'string']),
Rule::make('allowed_url_schemes')->rules(['required', 'array']),
],
]);

Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Classes/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,16 @@ public function exception_is_thrown_if_the_default_url_is_not_a_string(): void
$validation = new Validation();
$validation->validateConfig();
}

#[Test]
public function exception_is_thrown_if_the_allowed_url_schemes_is_not_an_array(): void
{
$this->expectException(ValidationException::class);
$this->expectExceptionMessage('The short-url.allowed_url_schemes field must be an array.');

Config::set('short-url.allowed_url_schemes', 'INVALID');

$validation = new Validation();
$validation->validateConfig();
}
}

0 comments on commit d95b881

Please sign in to comment.