Skip to content

Commit

Permalink
Add empty values to the date validator data provider
Browse files Browse the repository at this point in the history
Signed-off-by: George Steel <george@net-glue.co.uk>
  • Loading branch information
gsteel committed Sep 12, 2022
1 parent 01a9b41 commit 4bcb2b8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testSetFormatIgnoresNull(): void
/**
* @return array[]
* @psalm-return array<array{
* 0: string|numeric|DateTime|object|array,
* 0: string|numeric|DateTime|object|array|null,
* 1: null|string,
* 2: bool,
* 3: bool
Expand Down Expand Up @@ -97,31 +97,35 @@ public function datesDataProvider(): array
[new DateTime(), null, true, false],
// invalid obj
[new stdClass(), null, false, false],
// Empty Values
[[], null, false, false],
['', null, false, false],
[null, null, false, false],
];
}

/**
* Ensures that the validator follows expected behavior
*
* @dataProvider datesDataProvider
* @param string|numeric|DateTime|object|array $input
* @param string|numeric|DateTime|object|array|null $input
*/
public function testBasic($input, ?string $format, bool $result, bool $resultStrict): void
{
$this->validator->setFormat($format);
/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress ArgumentTypeCoercion, PossiblyNullArgument */
$this->assertEquals($result, $this->validator->isValid($input));
}

/**
* @dataProvider datesDataProvider
* @param string|numeric|DateTime|object|array $input
* @param string|numeric|DateTime|object|array|null $input
*/
public function testBasicStrictMode($input, ?string $format, bool $result, bool $resultStrict): void
{
$this->validator->setStrict(true);
$this->validator->setFormat($format);
/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress ArgumentTypeCoercion, PossiblyNullArgument */
$this->assertSame($resultStrict, $this->validator->isValid($input));
}

Expand Down

0 comments on commit 4bcb2b8

Please sign in to comment.