cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,29 +1,62 @@
<?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 Chill\PersonBundle\Tests\Validator\AccompanyingPeriod;
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\LocationValidityValidator;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Templating\Entity\PersonRender;
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\LocationValidity;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\LocationValidityValidator;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
/**
* @internal
* @coversNothing
*/
class LocationValidityValidatorTest extends ConstraintValidatorTestCase
{
public function testValidAddress()
public function testPeriodDoesNotContainsPersonOnAnyPerson()
{
$constraint = $this->getConstraint();
$period = new AccompanyingPeriod();
$person = new Person();
$period->addPerson($person);
$period->setPersonLocation($person);
$person1 = new Person();
$period->setPersonLocation($person1);
$this->validator->validate($period, $constraint);
$this->assertNoViolation();
$this->buildViolation('messagePersonLocatedMustBeAssociated')
->setParameters([
'{{ person_name }}' => 'name',
])
->assertRaised();
}
public function testPeriodDoesNotContainsPersonOnOtherPerson()
{
$constraint = $this->getConstraint();
$period = new AccompanyingPeriod();
$person1 = new Person();
$person2 = new Person();
$period->addPerson($person1);
$period->setPersonLocation($person2);
$this->validator->validate($period, $constraint);
$this->buildViolation('messagePersonLocatedMustBeAssociated')
->setParameters([
'{{ person_name }}' => 'name',
])
->assertRaised();
}
public function testPeriodDoesNotContainsPersonOnRemovedPerson()
@@ -41,50 +74,10 @@ class LocationValidityValidatorTest extends ConstraintValidatorTestCase
$this->validator->validate($period, $constraint);
$this->buildViolation('messagePersonLocatedMustBeAssociated')
->setParameters([
'{{ person_name }}' => 'name'
])
->assertRaised()
;
}
public function testPeriodDoesNotContainsPersonOnOtherPerson()
{
$constraint = $this->getConstraint();
$period = new AccompanyingPeriod();
$person1 = new Person();
$person2 = new Person();
$period->addPerson($person1);
$period->setPersonLocation($person2);
$this->validator->validate($period, $constraint);
$this->buildViolation('messagePersonLocatedMustBeAssociated')
->setParameters([
'{{ person_name }}' => 'name'
])
->assertRaised()
;
}
public function testPeriodDoesNotContainsPersonOnAnyPerson()
{
$constraint = $this->getConstraint();
$period = new AccompanyingPeriod();
$person1 = new Person();
$period->setPersonLocation($person1);
$this->validator->validate($period, $constraint);
$this->buildViolation('messagePersonLocatedMustBeAssociated')
->setParameters([
'{{ person_name }}' => 'name'
])
->assertRaised()
;
->setParameters([
'{{ person_name }}' => 'name',
])
->assertRaised();
}
public function testRemoveLocationOnPeriodValidated()
@@ -97,26 +90,38 @@ class LocationValidityValidatorTest extends ConstraintValidatorTestCase
$this->validator->validate($period, $constraint);
$this->buildViolation('messagePeriodMustRemainsLocated')
->assertRaised()
;
->assertRaised();
}
public function testValidAddress()
{
$constraint = $this->getConstraint();
$period = new AccompanyingPeriod();
$person = new Person();
$period->addPerson($person);
$period->setPersonLocation($person);
$this->validator->validate($period, $constraint);
$this->assertNoViolation();
}
protected function createValidator()
{
$render = $this->createMock(PersonRender::class);
$render->method('renderString')
->willReturn('name');
return new LocationValidityValidator($render);
}
protected function getConstraint()
{
return new LocationValidity([
'messagePersonLocatedMustBeAssociated' => 'messagePersonLocatedMustBeAssociated',
'messagePeriodMustRemainsLocated' => 'messagePeriodMustRemainsLocated'
'messagePeriodMustRemainsLocated' => 'messagePeriodMustRemainsLocated',
]);
}
protected function createValidator()
{
$render= $this->createMock(PersonRender::class);
$render->method('renderString')
->willReturn('name')
;
return new LocationValidityValidator($render);
}
}

View File

@@ -1,16 +1,28 @@
<?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 Chill\PersonBundle\Tests\Validator\Household;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Entity\Household\Position;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Templating\Entity\PersonRender;
use Chill\PersonBundle\Validator\Constraints\Household\HouseholdMembershipSequentialValidator;
use Chill\PersonBundle\Validator\Constraints\Household\HouseholdMembershipSequential;
use Chill\PersonBundle\Validator\Constraints\Household\HouseholdMembershipSequentialValidator;
use DateTimeImmutable;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
/**
* @internal
* @coversNothing
*/
class HouseholdMembershipSequentialValidatorTest extends ConstraintValidatorTestCase
{
public function testEmptyPerson()
@@ -20,7 +32,7 @@ class HouseholdMembershipSequentialValidatorTest extends ConstraintValidatorTest
$person = new Person();
$this->validator->validate($person, $constraint);
$this->assertNoViolation();
}
@@ -31,18 +43,15 @@ class HouseholdMembershipSequentialValidatorTest extends ConstraintValidatorTest
$person = new Person();
$household = new Household();
$position = (new Position())
->setShareHousehold(true)
;
->setShareHousehold(true);
$membership = (new HouseholdMember())
->setPosition($position)
->setStartDate(new \DateTimeImmutable('2010-01-01'))
->setPerson($person)
;
->setStartDate(new DateTimeImmutable('2010-01-01'))
->setPerson($person);
$membership = (new HouseholdMember())
->setPosition($position)
->setStartDate(new \DateTimeImmutable('2011-01-01'))
->setPerson($person)
;
->setStartDate(new DateTimeImmutable('2011-01-01'))
->setPerson($person);
$this->validator->validate($person, $constraint);
@@ -50,10 +59,9 @@ class HouseholdMembershipSequentialValidatorTest extends ConstraintValidatorTest
->setParameters([
'%person_name%' => 'name',
'%from%' => '01-01-2011',
'%nbHousehold%' => 2
'%nbHousehold%' => 2,
])
->assertRaised()
;
->assertRaised();
}
public function testMembershipCoveringNoShareHousehold()
@@ -63,38 +71,34 @@ class HouseholdMembershipSequentialValidatorTest extends ConstraintValidatorTest
$person = new Person();
$household = new Household();
$position = (new Position())
->setShareHousehold(false)
;
->setShareHousehold(false);
$membership = (new HouseholdMember())
->setPosition($position)
->setStartDate(new \DateTimeImmutable('2010-01-01'))
->setPerson($person)
;
->setStartDate(new DateTimeImmutable('2010-01-01'))
->setPerson($person);
$membership = (new HouseholdMember())
->setPosition($position)
->setStartDate(new \DateTimeImmutable('2011-01-01'))
->setPerson($person)
;
->setStartDate(new DateTimeImmutable('2011-01-01'))
->setPerson($person);
$this->validator->validate($person, $constraint);
$this->assertNoViolation();
}
protected function getConstraint()
{
return new HouseholdMembershipSequential([
'message' => 'msg'
]);
}
protected function createValidator()
{
$render = $this->createMock(PersonRender::class);
$render->method('renderString')
->willReturn('name')
;
->willReturn('name');
return new HouseholdMembershipSequentialValidator($render);
}
}
protected function getConstraint()
{
return new HouseholdMembershipSequential([
'message' => 'msg',
]);
}
}

View File

@@ -1,39 +1,28 @@
<?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 Chill\PersonBundle\Tests\Validator\Household;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Entity\Household\Position;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolderValidator;
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder;
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolderValidator;
use DateTimeImmutable;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
/**
* @internal
* @coversNothing
*/
class MaxHolderValidatorTest extends ConstraintValidatorTestCase
{
/**
* @dataProvider provideInvalidHousehold
*/
public function testHouseholdInvalid(Household $household, $parameters)
{
$constraint = $this->getConstraint();
$this->validator->validate($household, $constraint);
$this->buildViolation('msg')
->setParameters($parameters)
->assertRaised()
;
}
protected function getConstraint()
{
return new MaxHolder([
'message' => 'msg',
'messageInfinity' => 'msgInfinity'
]);
}
public function provideInvalidHousehold()
{
$household = new Household();
@@ -43,34 +32,57 @@ class MaxHolderValidatorTest extends ConstraintValidatorTestCase
->addMember(
(new HouseholdMember())
->setHolder(true)
->setStartDate(new \DateTimeImmutable('2010-01-01'))
->setEndDate(new \DateTimeImmutable('2010-12-01'))
)
->setStartDate(new DateTimeImmutable('2010-01-01'))
->setEndDate(new DateTimeImmutable('2010-12-01'))
)
->addMember(
(new HouseholdMember())
->setHolder(true)
->setStartDate(new \DateTimeImmutable('2010-06-01'))
->setEndDate(new \DateTimeImmutable('2010-07-01'))
)
->setStartDate(new DateTimeImmutable('2010-06-01'))
->setEndDate(new DateTimeImmutable('2010-07-01'))
)
->addMember(
(new HouseholdMember())
->setHolder(true)
->setStartDate(new \DateTimeImmutable('2010-01-01'))
->setEndDate(new \DateTimeImmutable('2010-12-01'))
)
;
->setStartDate(new DateTimeImmutable('2010-01-01'))
->setEndDate(new DateTimeImmutable('2010-12-01'))
);
yield [
$household,
$household,
[
'{{ start }}' => '01-06-2010',
'{{ end }}' => '01-07-2010'
]
'{{ start }}' => '01-06-2010',
'{{ end }}' => '01-07-2010',
],
];
}
/**
* @dataProvider provideInvalidHousehold
*
* @param mixed $parameters
*/
public function testHouseholdInvalid(Household $household, $parameters)
{
$constraint = $this->getConstraint();
$this->validator->validate($household, $constraint);
$this->buildViolation('msg')
->setParameters($parameters)
->assertRaised();
}
protected function createValidator()
{
return new MaxHolderValidator();
}
protected function getConstraint()
{
return new MaxHolder([
'message' => 'msg',
'messageInfinity' => 'msgInfinity',
]);
}
}

View File

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

View File

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

View File

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