Skip to content

Commit

Permalink
Add DateTimeValidationTest class
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Oct 7, 2021
1 parent ee2e611 commit 05230ab
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/DateTimeValidatorTest.php
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');
}
}

0 comments on commit 05230ab

Please sign in to comment.