Tests: Fix string length validation tests
This commit is contained in:
parent
599fff26d4
commit
fddae62669
|
@ -29,10 +29,14 @@ trait StringInputLength
|
|||
protected function isDateTime(mixed $input): bool
|
||||
{
|
||||
try {
|
||||
$input = new DateTime($input);
|
||||
$inputDateTime = new DateTime($input);
|
||||
$now = new DateTime();
|
||||
|
||||
// Min 1s diff to exclude any not auto-detected dates / times like ...
|
||||
return abs((int) (new DateTime())->diff($input)->format('%s')) > 1;
|
||||
} catch (Exception $e) {
|
||||
return abs($inputDateTime->getTimestamp() - $now->getTimestamp()) > 1
|
||||
// Different timezone to prevent interpreting the value as a timezone which happens with H
|
||||
&& $inputDateTime->getTimezone()->getName() != $input;
|
||||
} catch (Exception) {
|
||||
// Ignore it
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,11 @@ class BetweenTest extends TestCase
|
|||
{
|
||||
$rule = new Between(3, 10);
|
||||
$this->assertFalse($rule->validate(1));
|
||||
$this->assertFalse($rule->validate(2));
|
||||
$this->assertFalse($rule->validate('11'));
|
||||
$this->assertTrue($rule->validate(3));
|
||||
$this->assertTrue($rule->validate(5));
|
||||
$this->assertTrue($rule->validate(10));
|
||||
$this->assertFalse($rule->validate('AS'));
|
||||
$this->assertFalse($rule->validate('TestContentThatCounts'));
|
||||
$this->assertTrue($rule->validate('TESTING'));
|
||||
|
@ -25,6 +28,12 @@ class BetweenTest extends TestCase
|
|||
$rule = new Between('2042-01-01', '2042-10-10');
|
||||
$this->assertFalse($rule->validate('2000-01-01'));
|
||||
$this->assertFalse($rule->validate('3000-01-01'));
|
||||
$this->assertFalse($rule->validate('2041-12-31'));
|
||||
$this->assertFalse($rule->validate('2042-10-11'));
|
||||
$this->assertTrue($rule->validate('2042-05-11'));
|
||||
$this->assertTrue($rule->validate('2042-01-01'));
|
||||
$this->assertTrue($rule->validate('2042-01-02'));
|
||||
$this->assertTrue($rule->validate('2042-10-09'));
|
||||
$this->assertTrue($rule->validate('2042-10-10'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,16 @@ class MaxTest extends TestCase
|
|||
$this->assertFalse($rule->validate(10));
|
||||
$this->assertFalse($rule->validate('22'));
|
||||
$this->assertTrue($rule->validate(3));
|
||||
$this->assertTrue($rule->validate(2));
|
||||
$this->assertTrue($rule->validate(-10));
|
||||
$this->assertFalse($rule->validate('TEST'));
|
||||
$this->assertTrue($rule->validate('AS'));
|
||||
|
||||
$rule = new Max('2042-01-01');
|
||||
$this->assertFalse($rule->validate('2100-01-01'));
|
||||
$this->assertFalse($rule->validate('2042-01-02'));
|
||||
$this->assertTrue($rule->validate('2000-01-01'));
|
||||
$this->assertTrue($rule->validate('2041-12-31'));
|
||||
$this->assertTrue($rule->validate('2042-01-01'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,14 +15,19 @@ class MinTest extends TestCase
|
|||
public function testValidate(): void
|
||||
{
|
||||
$rule = new Min(3);
|
||||
$this->assertFalse($rule->validate(-10));
|
||||
$this->assertFalse($rule->validate(1));
|
||||
$this->assertFalse($rule->validate('2'));
|
||||
$this->assertTrue($rule->validate(3));
|
||||
$this->assertTrue($rule->validate(4));
|
||||
$this->assertFalse($rule->validate('AS'));
|
||||
$this->assertTrue($rule->validate('TEST'));
|
||||
|
||||
$rule = new Min('2042-01-01');
|
||||
$this->assertFalse($rule->validate('2000-01-01'));
|
||||
$this->assertFalse($rule->validate('2041-12-31'));
|
||||
$this->assertTrue($rule->validate('2042-01-01'));
|
||||
$this->assertTrue($rule->validate('2042-01-02'));
|
||||
$this->assertTrue($rule->validate('2345-01-01'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ class StringInputLengthTest extends TestCase
|
|||
['com', 3],
|
||||
['Test', 4],
|
||||
['H', 1],
|
||||
['Europe/Berlin', 13],
|
||||
['3', 3],
|
||||
[42, 42],
|
||||
[99.3, 99.3],
|
||||
|
|
Loading…
Reference in New Issue