-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee2e611
commit 05230ab
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace ipl\Tests\Validator; | ||
|
||
use DateTime; | ||
use ipl\I18n\NoopTranslator; | ||
use ipl\I18n\StaticTranslator; | ||
use ipl\Validator\DateTimeValidator; | ||
|
||
class DateTimeValidatorTest extends TestCase | ||
{ | ||
public function testDateTimeValidatorWithValidDateTime() | ||
{ | ||
StaticTranslator::$instance = new NoopTranslator(); | ||
$this->assertTrue((new DateTimeValidator())->isValid(new DateTime()), 'current date is a valid date'); | ||
} | ||
|
||
public function testDateTimeValidatorWithFalseAsDateTimeValue() | ||
{ | ||
StaticTranslator::$instance = new NoopTranslator(); | ||
$validator = new DateTimeValidator(); | ||
|
||
$this->assertFalse($validator->isValid(false), 'false is not a valid date'); | ||
} | ||
|
||
public function testDateTimeValidatorWithStringAsDateTimeValue() | ||
{ | ||
StaticTranslator::$instance = new NoopTranslator(); | ||
$validator = new DateTimeValidator(); | ||
|
||
$this->assertTrue($validator->isValid('2021-02-15T15:03:01'), '15th Feb is a valid date'); | ||
$this->assertFalse($validator->isValid('2021-02-31T15:03:01'), '31st Feb is not a valid date'); | ||
$this->assertFalse($validator->isValid('2021-02-03T26:03:01'), "26 o'clock is not a valid time"); | ||
$this->assertFalse($validator->isValid(''), 'Empty value is not a valid date'); | ||
} | ||
} |