Skip to content

Commit

Permalink
Validate the timeframe value (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm authored Aug 8, 2022
1 parent 97d4a63 commit 22e7b98
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public function getTimeFrameDisallowed()
if (empty($this->config->timeframe_disallowed)) {
return '';
}
$frame = $this->config->timeframe_disallowed;
$length = count(explode('-', $frame));
if ($length !== 2) {
throw new \InvalidArgumentException('The timeframe should consist of two 24 hour format times separated by a dash ("-")');
}
return $this->config->timeframe_disallowed;
}

Expand Down
6 changes: 5 additions & 1 deletion tests/UnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,12 @@ public function testTimezone($filename, $expected_result)
*
* @dataProvider getTimeframes
*/
public function testTimeframeDisallowed($filename, $expected_result)
public function testTimeframeDisallowed($filename, $expected_result, $throws = false)
{
$data = $this->createDataFromFixture($filename);
if ($throws) {
$this->expectException(\InvalidArgumentException::class);
}
self::assertEquals($expected_result, $data->getTimeFrameDisallowed());
}

Expand Down Expand Up @@ -545,6 +548,7 @@ public function getTimeframes()
[
'timeframe_disallowed4.json',
'does not really work, but value allowed',
true,
],
];
}
Expand Down

0 comments on commit 22e7b98

Please sign in to comment.