mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 11:03:50 +00:00
move birthday validator to namespace person + rewrite tests
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Validator\Person;
|
||||
|
||||
use Chill\PersonBundle\Validator\Constraints\Person\BirthdateValidator;
|
||||
use Chill\PersonBundle\Validator\Constraints\Person\Birthdate;
|
||||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
/**
|
||||
* Test the behaviour of BirthdayValidator
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class BirthdateValidatorTest extends ConstraintValidatorTestCase
|
||||
{
|
||||
|
||||
public function testValidateTodayInvalid()
|
||||
{
|
||||
$bornToday = new \DateTime('now');
|
||||
$this->validator->validate($bornToday, $this->createConstraint());
|
||||
$this->buildViolation('msg')
|
||||
->setParameter('%date%', (new \DateTime('yesterday'))->format('d-m-Y'))
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testValidateYesterdayValid()
|
||||
{
|
||||
$bornYesterday = new \DateTime('yesterday');
|
||||
$this->validator->validate($bornYesterday, $this->createConstraint());
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testTomorrowInvalid()
|
||||
{
|
||||
$bornAfter = new \DateTime('+2 days');
|
||||
$this->validator->validate($bornAfter, $this->createConstraint());
|
||||
$this->buildViolation('msg')
|
||||
->setParameter('%date%', (new \DateTime('yesterday'))->format('d-m-Y'))
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
private function createConstraint()
|
||||
{
|
||||
return new Birthdate([
|
||||
'message' => 'msg'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new BirthdateValidator('P1D');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user