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,12 +1,23 @@
<?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\Entity\AccompanyingPeriod;
use PHPUnit\Framework\TestCase;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
use Chill\PersonBundle\Entity\Person;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use PHPUnit\Framework\TestCase;
/**
* @internal
* @coversNothing
*/
class ResourceTest extends TestCase
{
public function testSetResource()
@@ -22,7 +33,7 @@ class ResourceTest extends TestCase
$this->assertNull($resource->getThirdParty());
$resource->setResource($thirdParty);
$this->assertSame($thirdParty, $resource->getResource());
$this->assertNull($resource->getPerson());

View File

@@ -1,39 +1,42 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.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/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Entity;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Person;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
use DateTime;
use DateTimeInterface;
/**
* @internal
* @coversNothing
*/
class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
{
public function testClosingEqualOpening()
{
$datetime = new DateTime('now');
$period = new AccompanyingPeriod($datetime);
$period->setClosingDate($datetime);
$this->assertTrue($period->isClosingAfterOpening());
}
public function testClosingIsAfterOpeningConsistency()
{
$datetime1 = new \DateTime('now');
$datetime2 = new \DateTime('tomorrow');
$datetime1 = new DateTime('now');
$datetime2 = new DateTime('tomorrow');
$period = new AccompanyingPeriod($datetime1);
$period->setClosingDate($datetime2);
@@ -45,8 +48,8 @@ class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
public function testClosingIsBeforeOpeningConsistency()
{
$datetime1 = new \DateTime('tomorrow');
$datetime2 = new \DateTime('now');
$datetime1 = new DateTime('tomorrow');
$datetime2 = new DateTime('now');
$period = new AccompanyingPeriod($datetime1);
$period->setClosingDate($datetime2);
@@ -54,37 +57,53 @@ class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
$this->assertFalse($period->isClosingAfterOpening());
}
public function testClosingEqualOpening()
public function testInitialComment()
{
$datetime = new \DateTime('now');
$period = new AccompanyingPeriod(new DateTime());
$comment = new Comment();
$replacingComment = new Comment();
$period = new AccompanyingPeriod($datetime);
$period->setClosingDate($datetime);
$period->setInitialComment(null);
$this->assertNull($period->getInitialComment());
$this->assertTrue($period->isClosingAfterOpening());
}
$period->setInitialComment($comment);
$this->assertSame($period->getInitialComment(), $comment);
$this->assertSame($period, $comment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments');
public function testIsOpen()
{
$period = new AccompanyingPeriod(new \DateTime());
$period->setInitialComment($replacingComment);
$this->assertSame($period->getInitialComment(), $replacingComment);
$this->assertSame($period, $replacingComment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments');
$this->assertNull($comment->getAccompanyingPeriod());
$this->assertTrue($period->isOpen());
$period->setInitialComment(null);
$this->assertNull($period->getInitialComment());
$this->assertNull($replacingComment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), 'The initial comment should not appears in the list of comments');
}
public function testIsClosed()
{
$period = new AccompanyingPeriod(new \DateTime());
$period->setClosingDate(new \DateTime('tomorrow'));
$period = new AccompanyingPeriod(new DateTime());
$period->setClosingDate(new DateTime('tomorrow'));
$this->assertFalse($period->isOpen());
}
public function testIsOpen()
{
$period = new AccompanyingPeriod(new DateTime());
$this->assertTrue($period->isOpen());
}
public function testPersonPeriod()
{
$person = new Person();
$person2 = new Person();
$person3 = new Person();
$period = new AccompanyingPeriod(new \DateTime());
$period = new AccompanyingPeriod(new DateTime());
$participation0 = $period->createParticipationFor($person);
$period->createParticipationFor($person2);
@@ -104,7 +123,7 @@ class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
$participationL = $period->closeParticipationFor($person);
$this->assertSame($participationL, $participation);
$this->assertTrue($participation->getEndDate() instanceof \DateTimeInterface);
$this->assertTrue($participation->getEndDate() instanceof DateTimeInterface);
$participation = $period->getOpenParticipationContainsPerson($person);
$this->assertNull($participation);
@@ -125,7 +144,7 @@ class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
public function testRequestor()
{
$period = new AccompanyingPeriod(new \DateTime());
$period = new AccompanyingPeriod(new DateTime());
$person = new Person();
$thirdParty = new ThirdParty();
@@ -143,35 +162,9 @@ class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
$this->assertSame($thirdParty, $period->getRequestorThirdParty());
$this->assertSame($thirdParty, $period->getRequestor());
$period->setRequestor(NULL);
$period->setRequestor(null);
$this->assertNull($period->getRequestorThirdParty());
$this->assertNull($period->getRequestorPerson());
$this->assertNull($period->getRequestor());
}
public function testInitialComment()
{
$period = new AccompanyingPeriod(new \DateTime());
$comment = new Comment();
$replacingComment = new Comment();
$period->setInitialComment(NULL);
$this->assertNull($period->getInitialComment());
$period->setInitialComment($comment);
$this->assertSame($period->getInitialComment(), $comment);
$this->assertSame($period, $comment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments");
$period->setInitialComment($replacingComment);
$this->assertSame($period->getInitialComment(), $replacingComment);
$this->assertSame($period, $replacingComment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments");
$this->assertNull($comment->getAccompanyingPeriod());
$period->setInitialComment(NULL);
$this->assertNull($period->getInitialComment());
$this->assertNull($replacingComment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments");
}
}

View File

@@ -1,34 +1,41 @@
<?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 Bundle\ChillPersonBundle\Tests\Entity\Household;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Entity\Household\Position;
use PHPUnit\Framework\TestCase;
/**
* @internal
* @coversNothing
*/
class HouseholdMemberTest extends TestCase
{
public function testPositionSharehousehold()
{
$position = (new Position())
->setShareHousehold(true)
;
$membership = (new HouseholdMember())
->setPosition($position)
;
$this->assertTrue($membership->getShareHousehold());
}
public function testPositionDoNotSharehousehold()
{
$position = (new Position())
->setShareHousehold(false)
;
->setShareHousehold(false);
$membership = (new HouseholdMember())
->setPosition($position)
;
->setPosition($position);
$this->assertFalse($membership->getShareHousehold());
}
public function testPositionSharehousehold()
{
$position = (new Position())
->setShareHousehold(true);
$membership = (new HouseholdMember())
->setPosition($position);
$this->assertTrue($membership->getShareHousehold());
}
}

View File

@@ -1,111 +1,48 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@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/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Entity;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
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\Entity\AccompanyingPeriod;
use Chill\MainBundle\Entity\Address;
use DateInterval;
use DateTime;
use Generator;
use DateTimeImmutable;
/**
* Unit tests for the person Entity
* Unit tests for the person Entity.
*
* @internal
* @coversNothing
*/
class PersonTest extends \PHPUnit\Framework\TestCase
{
/**
* Test the creation of an accompanying, its closure and the access to
* the current accompaniying period via the getCurrentAccompanyingPeriod
* function.
*/
public function testGetCurrentAccompanyingPeriod()
{
$d = new \DateTime('yesterday');
$p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$period = $p->getCurrentAccompanyingPeriod();
$this->assertInstanceOf(AccompanyingPeriod::class, $period);
$this->assertTrue($period->isOpen());
$this->assertEquals($d, $period->getOpeningDate());
//close and test
$period->setClosingDate(new \DateTime('tomorrow'));
$shouldBeNull = $p->getCurrentAccompanyingPeriod();
$this->assertNull($shouldBeNull);
}
/**
* Test if the getAccompanyingPeriodsOrdered function return a list of
* periods ordered ascendency.
*/
public function testAccompanyingPeriodOrderWithUnorderedAccompanyingPeriod()
{
$d = new \DateTime("2013/2/1");
$p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period);
$f = new \DateTime("2013/1/1");
$p->open(new AccompanyingPeriod($f));
$g = new \DateTime("2013/4/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
$p->close($period);
$r = $p->getAccompanyingPeriodsOrdered();
$date = $r[0]->getOpeningDate()->format('Y-m-d');
$this->assertEquals($date, '2013-01-01');
}
/**
* Test if the getAccompanyingPeriodsOrdered function, for periods
* starting at the same time order regarding to the closing date.
*/
public function testAccompanyingPeriodOrderSameDateOpening() {
$d = new \DateTime("2013/2/1");
public function testAccompanyingPeriodOrderSameDateOpening()
{
$d = new DateTime('2013/2/1');
$p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$g = new \DateTime("2013/4/1");
$g = new DateTime('2013/4/1');
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
$p->close($period);
$f = new \DateTime("2013/2/1");
$f = new DateTime('2013/2/1');
$p->open(new AccompanyingPeriod($f));
$e = new \DateTime("2013/3/1");
$e = new DateTime('2013/3/1');
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period);
@@ -117,23 +54,52 @@ class PersonTest extends \PHPUnit\Framework\TestCase
}
/**
* Test if the function checkAccompanyingPeriodIsNotCovering returns
* the good constant when two periods are collapsing : a period
* is covering another one : start_1 < start_2 & end_2 < end_1
* Test if the getAccompanyingPeriodsOrdered function return a list of
* periods ordered ascendency.
*/
public function testDateCoveringWithCoveringAccompanyingPeriod() {
$d = new \DateTime("2013/2/1");
public function testAccompanyingPeriodOrderWithUnorderedAccompanyingPeriod()
{
$d = new DateTime('2013/2/1');
$p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$e = new \DateTime("2013/3/1");
$e = new DateTime('2013/3/1');
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period);
$f = new \DateTime("2013/1/1");
$f = new DateTime('2013/1/1');
$p->open(new AccompanyingPeriod($f));
$g = new \DateTime("2013/4/1");
$g = new DateTime('2013/4/1');
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
$p->close($period);
$r = $p->getAccompanyingPeriodsOrdered();
$date = $r[0]->getOpeningDate()->format('Y-m-d');
$this->assertEquals($date, '2013-01-01');
}
/**
* Test if the function checkAccompanyingPeriodIsNotCovering returns
* the good constant when two periods are collapsing : a period
* is covering another one : start_1 < start_2 & end_2 < end_1.
*/
public function testDateCoveringWithCoveringAccompanyingPeriod()
{
$d = new DateTime('2013/2/1');
$p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$e = new DateTime('2013/3/1');
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period);
$f = new DateTime('2013/1/1');
$p->open(new AccompanyingPeriod($f));
$g = new DateTime('2013/4/1');
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
$p->close($period);
@@ -143,25 +109,27 @@ class PersonTest extends \PHPUnit\Framework\TestCase
}
/**
* Test if the function checkAccompanyingPeriodIsNotCovering returns
* the good constant when two periods are collapsing : a period is open
* before an existing period
* Test the creation of an accompanying, its closure and the access to
* the current accompaniying period via the getCurrentAccompanyingPeriod
* function.
*/
public function testNotOpenAFileReOpenedLater() {
$d = new \DateTime("2013/2/1");
public function testGetCurrentAccompanyingPeriod()
{
$d = new DateTime('yesterday');
$p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period);
$period = $p->getCurrentAccompanyingPeriod();
$f = new \DateTime("2013/1/1");
$p->open(new AccompanyingPeriod($f));
$this->assertInstanceOf(AccompanyingPeriod::class, $period);
$this->assertTrue($period->isOpen());
$this->assertEquals($d, $period->getOpeningDate());
$r = $p->checkAccompanyingPeriodsAreNotCollapsing();
//close and test
$period->setClosingDate(new DateTime('tomorrow'));
$this->assertEquals($r['result'], Person::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD);
$shouldBeNull = $p->getCurrentAccompanyingPeriod();
$this->assertNull($shouldBeNull);
}
public function testIsSharingHousehold()
@@ -174,19 +142,17 @@ class PersonTest extends \PHPUnit\Framework\TestCase
->setShareHousehold(false);
$membership1 = (new HouseholdMember())
->setStartDate(new \DateTimeImmutable('10 years ago'))
->setEndDate(new \DateTimeImmutable('5 years ago'))
->setStartDate(new DateTimeImmutable('10 years ago'))
->setEndDate(new DateTimeImmutable('5 years ago'))
->setPerson($person)
->setPosition($positionShare)
;
->setPosition($positionShare);
$household->addMember($membership1);
$membership2 = (new HouseholdMember())
->setStartDate(new \DateTimeImmutable('4 years ago'))
->setEndDate(new \DateTimeImmutable('2 years ago'))
->setStartDate(new DateTimeImmutable('4 years ago'))
->setEndDate(new DateTimeImmutable('2 years ago'))
->setPerson($person)
->setPosition($positionNotShare)
;
->setPosition($positionNotShare);
$household->addMember($membership2);
$this->assertEquals(2, $person->getHouseholdParticipations()
@@ -194,9 +160,33 @@ class PersonTest extends \PHPUnit\Framework\TestCase
$this->assertFalse($person->isSharingHousehold());
$this->assertTrue($person->isSharingHousehold(
new \DateTimeImmutable('6 years ago')));
new DateTimeImmutable('6 years ago')
));
$this->assertFalse($person->isSharingHousehold(
new \DateTimeImmutable('3 years ago')));
new DateTimeImmutable('3 years ago')
));
}
/**
* Test if the function checkAccompanyingPeriodIsNotCovering returns
* the good constant when two periods are collapsing : a period is open
* before an existing period.
*/
public function testNotOpenAFileReOpenedLater()
{
$d = new DateTime('2013/2/1');
$p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$e = new DateTime('2013/3/1');
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period);
$f = new DateTime('2013/1/1');
$p->open(new AccompanyingPeriod($f));
$r = $p->checkAccompanyingPeriodsAreNotCollapsing();
$this->assertEquals($r['result'], Person::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD);
}
}

View File

@@ -1,13 +1,42 @@
<?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\Entity\SocialWork;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Doctrine\Common\Collections\ArrayCollection;
use PHPUnit\Framework\TestCase;
/**
* @internal
* @coversNothing
*/
class SocialIssueTest extends TestCase
{
public function testFindSocialIssuesAncestors()
{
$socialIssues = new ArrayCollection([
$parent = new SocialIssue(),
$child = (new SocialIssue())->setParent($parent),
$grandChild = (new SocialIssue())->setParent($child),
$grandGrandChild = (new SocialIssue())->setParent($grandChild),
$unrelated = new SocialIssue(),
]);
$ancestors = SocialIssue::findAncestorSocialIssues($socialIssues);
$this->assertCount(3, $ancestors);
$this->assertContains($parent, $ancestors);
$this->assertContains($child, $ancestors);
$this->assertContains($grandChild, $ancestors);
}
public function testIsDescendantOf()
{
$parent = new SocialIssue();
@@ -30,22 +59,4 @@ class SocialIssueTest extends TestCase
$this->assertFalse($child->isDescendantOf($grandChild));
}
public function testFindSocialIssuesAncestors()
{
$socialIssues = new ArrayCollection([
$parent = new SocialIssue(),
$child = (new SocialIssue())->setParent($parent),
$grandChild = (new SocialIssue())->setParent($child),
$grandGrandChild = (new SocialIssue())->setParent($grandChild),
$unrelated = new SocialIssue(),
]);
$ancestors = SocialIssue::findAncestorSocialIssues($socialIssues);
$this->assertCount(3, $ancestors);
$this->assertContains($parent, $ancestors);
$this->assertContains($child, $ancestors);
$this->assertContains($grandChild, $ancestors);
}
}