-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from paulotokimatu/fix/specify-error-in-dateti…
…me-constraint Added error message in DateTime constraint.
- Loading branch information
Showing
2 changed files
with
44 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
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Linio\Component\Input\Constraint; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class DateTimeTest extends TestCase | ||
{ | ||
public function testIsCheckingInvalidData() | ||
{ | ||
$constraint = new DateTime(); | ||
$this->assertFalse($constraint->validate('[email protected]')); | ||
$this->assertFalse($constraint->validate('2018-01-99')); | ||
$this->assertFalse($constraint->validate(123)); | ||
} | ||
|
||
public function testIsCheckingValidData() | ||
{ | ||
$constraint = new DateTime(); | ||
$this->assertTrue($constraint->validate('2018-01-01')); | ||
$this->assertTrue($constraint->validate('2010-12-31T00:00:00+00:00')); | ||
$this->assertTrue($constraint->validate('2006-12-12 10:00:00.5')); | ||
} | ||
|
||
public function testIsGettingErrorMessage() | ||
{ | ||
$constraint = new DateTime(); | ||
$this->assertFalse($constraint->validate('foo/bar')); | ||
$this->assertEquals('[field] Invalid date/time format', $constraint->getErrorMessage('field')); | ||
} | ||
|
||
public function testErrorMessageIsCustomizable() | ||
{ | ||
$constraint = new DateTime('CUSTOM!'); | ||
$this->assertSame('[field] CUSTOM!', $constraint->getErrorMessage('field')); | ||
} | ||
} |