move birthday validator to namespace person + rewrite tests

This commit is contained in:
2021-09-01 14:41:27 +02:00
parent eec798cfd3
commit 7faddbe3fe
4 changed files with 86 additions and 131 deletions

View File

@@ -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');
}
}