-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] DatetimeChecker error message for: after, before (#17)
- Loading branch information
Showing
3 changed files
with
95 additions
and
2 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
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,43 @@ | ||
<?php | ||
|
||
namespace Spiral\Validator\Tests\Functional; | ||
|
||
use Spiral\Validation\ValidationInterface; | ||
|
||
/** | ||
* @coversDefaultClass \Spiral\Validator\Checker\DatetimeChecker | ||
*/ | ||
final class DatetimeCheckerTest extends BaseTest | ||
{ | ||
/** | ||
* @covers ::after | ||
*/ | ||
public function testBeforeAfterErrorMessage(): void | ||
{ | ||
/** @var ValidationInterface $v */ | ||
$v = $this->getContainer()->get(ValidationInterface::class); | ||
$this->assertNotNull($v); | ||
$res = $v->validate( | ||
[ | ||
'dateBefore' => '2024-12-12', | ||
'dateAfter' => '2004-01-01', | ||
], | ||
[ | ||
'dateBefore' => [ | ||
['datetime::before', 'dateAfter'], | ||
], | ||
'dateAfter' => [ | ||
['datetime::after', 'dateBefore'], | ||
], | ||
], | ||
); | ||
$this->assertFalse($res->isValid()); | ||
$this->assertEquals( | ||
[ | ||
'dateBefore' => 'Value dateBefore should come before value dateAfter.', | ||
'dateAfter' => 'Value dateAfter should come after value dateBefore.', | ||
], | ||
$res->getErrors(), | ||
); | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
namespace Spiral\Validator\Tests\Functional; | ||
|
||
use Spiral\Validation\ValidationInterface; | ||
|
||
/** | ||
* @coversDefaultClass \Spiral\Validator\Checker\NumberChecker | ||
*/ | ||
final class NumberCheckerTest extends BaseTest | ||
{ | ||
/** | ||
* @covers ::range | ||
* @covers ::higher | ||
* @covers ::lower | ||
*/ | ||
public function testBeforeAfterErrorMessage(): void | ||
{ | ||
/** @var ValidationInterface $v */ | ||
$v = $this->getContainer()->get(ValidationInterface::class); | ||
$this->assertNotNull($v); | ||
$res = $v->validate( | ||
[ | ||
'inRange' => 10, | ||
'higher' => 1, | ||
'lower' => 20, | ||
], | ||
[ | ||
'inRange' => [ | ||
['number::range', 1, 5], | ||
], | ||
'higher' => [ | ||
['number::higher', 10], | ||
], | ||
'lower' => [ | ||
['number::lower', 10], | ||
], | ||
], | ||
); | ||
$this->assertFalse($res->isValid()); | ||
$this->assertEquals( | ||
[ | ||
'inRange' => 'Your value should be in range of 1-5.', | ||
'higher' => 'Your value should be equal to or higher than 10.', | ||
'lower' => 'Your value should be equal to or lower than 10.', | ||
], | ||
$res->getErrors(), | ||
); | ||
} | ||
} |