mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 11:03:50 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,74 +1,63 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Validator\Person;
|
||||
|
||||
use Chill\PersonBundle\Validator\Constraints\Person\BirthdateValidator;
|
||||
use Chill\PersonBundle\Validator\Constraints\Person\Birthdate;
|
||||
use Chill\PersonBundle\Validator\Constraints\Person\BirthdateValidator;
|
||||
use DateTime;
|
||||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
|
||||
/**
|
||||
* Test the behaviour of BirthdayValidator
|
||||
* Test the behaviour of BirthdayValidator.
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class BirthdateValidatorTest extends ConstraintValidatorTestCase
|
||||
{
|
||||
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'))
|
||||
->setCode('3f42fd96-0b2d-11ec-8cf3-0f3b1b1ca1c4')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testValidateTodayInvalid()
|
||||
{
|
||||
$bornToday = new \DateTime('now');
|
||||
$bornToday = new DateTime('now');
|
||||
$this->validator->validate($bornToday, $this->createConstraint());
|
||||
$this->buildViolation('msg')
|
||||
->setParameter('%date%', (new \DateTime('yesterday'))->format('d-m-Y'))
|
||||
->setParameter('%date%', (new DateTime('yesterday'))->format('d-m-Y'))
|
||||
->setCode('3f42fd96-0b2d-11ec-8cf3-0f3b1b1ca1c4')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testValidateYesterdayValid()
|
||||
{
|
||||
$bornYesterday = new \DateTime('yesterday');
|
||||
$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'))
|
||||
->setCode('3f42fd96-0b2d-11ec-8cf3-0f3b1b1ca1c4')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
private function createConstraint()
|
||||
{
|
||||
return new Birthdate([
|
||||
'message' => 'msg'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
return new BirthdateValidator('P1D');
|
||||
}
|
||||
|
||||
private function createConstraint()
|
||||
{
|
||||
return new Birthdate([
|
||||
'message' => 'msg',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Validator\Person;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenter;
|
||||
@@ -13,6 +19,10 @@ use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenterValidator;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class PersonHasCenterValidatorTest extends ConstraintValidatorTestCase
|
||||
{
|
||||
public function testValidateRequired()
|
||||
@@ -30,13 +40,6 @@ class PersonHasCenterValidatorTest extends ConstraintValidatorTestCase
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
protected function getConstraint()
|
||||
{
|
||||
return new PersonHasCenter([
|
||||
'message' => 'msg'
|
||||
]);
|
||||
}
|
||||
|
||||
protected function createValidator()
|
||||
{
|
||||
$parameterBag = $this->createMock(ParameterBagInterface::class);
|
||||
@@ -45,12 +48,19 @@ class PersonHasCenterValidatorTest extends ConstraintValidatorTestCase
|
||||
->with($this->equalTo('chill_person'))
|
||||
->willReturn([
|
||||
'validation' => [
|
||||
'center_required' => true
|
||||
]
|
||||
'center_required' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
$centerResolverDispatcher = $this->createMock(CenterResolverDispatcherInterface::class);
|
||||
|
||||
return new PersonHasCenterValidator($parameterBag, $centerResolverDispatcher);
|
||||
}
|
||||
|
||||
protected function getConstraint()
|
||||
{
|
||||
return new PersonHasCenter([
|
||||
'message' => 'msg',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Validator\Person;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Validator\Constraints\Person\Birthdate;
|
||||
use Datetime;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use function str_repeat;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class PersonValidationTest extends KernelTestCase
|
||||
{
|
||||
private ValidatorInterface $validator;
|
||||
@@ -18,38 +31,47 @@ class PersonValidationTest extends KernelTestCase
|
||||
$this->validator = self::$container->get(ValidatorInterface::class);
|
||||
}
|
||||
|
||||
public function testFirstnameValidation()
|
||||
{
|
||||
$person = (new Person())
|
||||
->setFirstname(\str_repeat('a', 500));
|
||||
$errors = $this->validator->validate($person, null, ["creation"]);
|
||||
foreach ($errors->getIterator() as $error) {
|
||||
if (Length::TOO_LONG_ERROR === $error->getCode()) {
|
||||
$this->assertTrue(true,
|
||||
"error code for firstname too long is present");
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->assertTrue(false,
|
||||
"error code for fistname too long is present");
|
||||
|
||||
}
|
||||
|
||||
public function testBirthdateInFuture()
|
||||
{
|
||||
$person = (new Person())
|
||||
->setBirthdate(new \Datetime('+2 months'));
|
||||
$errors = $this->validator->validate($person, null, ["creation"]);
|
||||
->setBirthdate(new Datetime('+2 months'));
|
||||
$errors = $this->validator->validate($person, null, ['creation']);
|
||||
|
||||
foreach ($errors->getIterator() as $error) {
|
||||
if (Birthdate::BIRTHDATE_INVALID_CODE === $error->getCode()) {
|
||||
$this->assertTrue(true,
|
||||
"error code for birthdate invalid is present");
|
||||
$this->assertTrue(
|
||||
true,
|
||||
'error code for birthdate invalid is present'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->assertTrue(false,
|
||||
"error code for birthdate invalid is present");
|
||||
|
||||
$this->assertTrue(
|
||||
false,
|
||||
'error code for birthdate invalid is present'
|
||||
);
|
||||
}
|
||||
|
||||
public function testFirstnameValidation()
|
||||
{
|
||||
$person = (new Person())
|
||||
->setFirstname(str_repeat('a', 500));
|
||||
$errors = $this->validator->validate($person, null, ['creation']);
|
||||
|
||||
foreach ($errors->getIterator() as $error) {
|
||||
if (Length::TOO_LONG_ERROR === $error->getCode()) {
|
||||
$this->assertTrue(
|
||||
true,
|
||||
'error code for firstname too long is present'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->assertTrue(
|
||||
false,
|
||||
'error code for fistname too long is present'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user