mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 14:25:00 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -17,16 +17,15 @@ use Chill\PersonBundle\Entity\Household\Position;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent;
|
||||
use Chill\PersonBundle\Household\MembersEditorFactory;
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
final class MembersEditorTest extends TestCase
|
||||
@@ -50,13 +49,13 @@ final class MembersEditorTest extends TestCase
|
||||
$factory = $this->buildMembersEditorFactory();
|
||||
$editor = $factory->createEditor($household);
|
||||
|
||||
$editor->addMovement($aMonthAgo = new DateTimeImmutable('1 month ago'), $person, $position);
|
||||
$editor->addMovement($aMonthAgo = new \DateTimeImmutable('1 month ago'), $person, $position);
|
||||
|
||||
// set a second time the person in position
|
||||
$factory = $this->buildMembersEditorFactory();
|
||||
$editor = $factory->createEditor($household);
|
||||
|
||||
$editor->addMovement($yesterday = new DateTimeImmutable('yesterday'), $person, $position);
|
||||
$editor->addMovement($yesterday = new \DateTimeImmutable('yesterday'), $person, $position);
|
||||
|
||||
$this->assertCount(2, $person->getHouseholdParticipationsNotShareHousehold());
|
||||
|
||||
@@ -75,8 +74,7 @@ final class MembersEditorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* We test that a leave move is possible when member startdate is same as current date
|
||||
*
|
||||
* We test that a leave move is possible when member startdate is same as current date.
|
||||
*/
|
||||
public function testLeaveMovementInSameHouseholdFromShareHouseholdToNotShareHouseholdOnSameDate()
|
||||
{
|
||||
@@ -90,7 +88,7 @@ final class MembersEditorTest extends TestCase
|
||||
|
||||
// create add move
|
||||
$editor = $factory->createEditor($household);
|
||||
$editor->addMovement(new DateTimeImmutable('today'), $person, $positionSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('today'), $person, $positionSharing);
|
||||
$editor->postMove();
|
||||
|
||||
self::assertContains($person, $household->getCurrentPersons());
|
||||
@@ -107,7 +105,7 @@ final class MembersEditorTest extends TestCase
|
||||
null
|
||||
);
|
||||
$editor = $factory->createEditor($household);
|
||||
$editor->addMovement(new DateTimeImmutable('today'), $person, $positionNotSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('today'), $person, $positionNotSharing);
|
||||
$editor->postMove();
|
||||
|
||||
$participations = $household->getMembers();
|
||||
@@ -120,7 +118,7 @@ final class MembersEditorTest extends TestCase
|
||||
self::assertCount(1, $notSharing);
|
||||
|
||||
self::assertNotNull($sharing[0]->getEndDate());
|
||||
self::assertEquals(new DateTimeImmutable('today'), $sharing[0]->getEndDate());
|
||||
self::assertEquals(new \DateTimeImmutable('today'), $sharing[0]->getEndDate());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +139,7 @@ final class MembersEditorTest extends TestCase
|
||||
$editor = $factory->createEditor($household);
|
||||
|
||||
// we add the member to the household
|
||||
$editor->addMovement(new DateTimeImmutable('1 month ago'), $person, $positionSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('1 month ago'), $person, $positionSharing);
|
||||
|
||||
// double check that the person is in the household
|
||||
$this->assertContains($person, $household->getCurrentPersons());
|
||||
@@ -156,7 +154,7 @@ final class MembersEditorTest extends TestCase
|
||||
null
|
||||
);
|
||||
$editor = $factory->createEditor($household2 = new Household());
|
||||
$editor->addMovement(new DateTimeImmutable('yesterday'), $person, $positionNotSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('yesterday'), $person, $positionNotSharing);
|
||||
$editor->postMove();
|
||||
|
||||
$sharings = $household->getCurrentMembers()->filter(static fn (HouseholdMember $m) => $m->getShareHousehold());
|
||||
@@ -186,7 +184,7 @@ final class MembersEditorTest extends TestCase
|
||||
$editor = $factory->createEditor($household);
|
||||
|
||||
// we add the member to the household
|
||||
$editor->addMovement(new DateTimeImmutable('1 month ago'), $person, $positionSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('1 month ago'), $person, $positionSharing);
|
||||
|
||||
// double check that the person is in the household
|
||||
$this->assertContains($person, $household->getCurrentPersons());
|
||||
@@ -201,7 +199,7 @@ final class MembersEditorTest extends TestCase
|
||||
null
|
||||
);
|
||||
$editor = $factory->createEditor($household);
|
||||
$editor->addMovement(new DateTimeImmutable('yesterday'), $person, $positionNotSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('yesterday'), $person, $positionNotSharing);
|
||||
$editor->postMove();
|
||||
|
||||
$sharings = $household->getCurrentMembers()->filter(static fn (HouseholdMember $m) => $m->getShareHousehold());
|
||||
@@ -231,14 +229,14 @@ final class MembersEditorTest extends TestCase
|
||||
$editor = $factory->createEditor($household);
|
||||
|
||||
// we add the member to the household, at the position "not sharing"
|
||||
$editor->addMovement(new DateTimeImmutable('1 month ago'), $person, $positionNotSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('1 month ago'), $person, $positionNotSharing);
|
||||
|
||||
// double check that the person is in the household
|
||||
$this->assertContains($person, $household->getCurrentPersons());
|
||||
|
||||
// we do the move to the position sharing household
|
||||
$editor = $factory->createEditor($household);
|
||||
$editor->addMovement(new DateTimeImmutable('yesterday'), $person, $positionSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('yesterday'), $person, $positionSharing);
|
||||
|
||||
self::assertCount(2, $household->getMembers());
|
||||
|
||||
@@ -270,14 +268,14 @@ final class MembersEditorTest extends TestCase
|
||||
$editor = $factory->createEditor($household);
|
||||
|
||||
// we add the member to the household, at the position "not sharing"
|
||||
$editor->addMovement(new DateTimeImmutable('today'), $person, $positionNotSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('today'), $person, $positionNotSharing);
|
||||
|
||||
// double check that the person is in the household
|
||||
$this->assertContains($person, $household->getCurrentPersons());
|
||||
|
||||
// we do the move to the position sharing household
|
||||
$editor = $factory->createEditor($household);
|
||||
$editor->addMovement(new DateTimeImmutable('today'), $person, $positionSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('today'), $person, $positionSharing);
|
||||
|
||||
self::assertCount(2, $household->getMembers());
|
||||
|
||||
@@ -303,20 +301,20 @@ final class MembersEditorTest extends TestCase
|
||||
$editor = $this->factory->createEditor($household1);
|
||||
|
||||
$editor->addMovement(
|
||||
DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'),
|
||||
\DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'),
|
||||
$person,
|
||||
$position
|
||||
);
|
||||
|
||||
$persistables = $editor->getPersistable();
|
||||
$this->assertEquals(1, count($persistables));
|
||||
$this->assertEquals(1, \count($persistables));
|
||||
|
||||
$membership1 = $person->getHouseholdParticipations()->first();
|
||||
$this->assertSame($household1, $membership1->getHousehold());
|
||||
$this->assertNull($membership1->getEndDate());
|
||||
|
||||
// move to another household
|
||||
$date = DateTimeImmutable::createFromFormat('Y-m-d', '2021-01-01');
|
||||
$date = \DateTimeImmutable::createFromFormat('Y-m-d', '2021-01-01');
|
||||
$editor = $this->factory->createEditor($household2);
|
||||
$editor->addMovement(
|
||||
$date,
|
||||
@@ -325,7 +323,7 @@ final class MembersEditorTest extends TestCase
|
||||
);
|
||||
|
||||
$persistables = $editor->getPersistable();
|
||||
$this->assertEquals(1, count($persistables));
|
||||
$this->assertEquals(1, \count($persistables));
|
||||
|
||||
$membership2 = $person->getHouseholdParticipations()->last();
|
||||
$this->assertNull($membership2->getEndDate());
|
||||
@@ -346,20 +344,20 @@ final class MembersEditorTest extends TestCase
|
||||
$editor = $this->factory->createEditor($household1);
|
||||
|
||||
$editor->addMovement(
|
||||
DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'),
|
||||
\DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'),
|
||||
$person,
|
||||
$position
|
||||
);
|
||||
|
||||
$persistables = $editor->getPersistable();
|
||||
$this->assertEquals(count($persistables), 1);
|
||||
$this->assertEquals(\count($persistables), 1);
|
||||
|
||||
$membership1 = $persistables[0];
|
||||
$this->assertSame($household1, $membership1->getHousehold());
|
||||
$this->assertNull($membership1->getEndDate());
|
||||
|
||||
// move to another household
|
||||
$date = DateTimeImmutable::createFromFormat('Y-m-d', '2021-01-01');
|
||||
$date = \DateTimeImmutable::createFromFormat('Y-m-d', '2021-01-01');
|
||||
$editor = $this->factory->createEditor($household2);
|
||||
$editor->addMovement(
|
||||
$date,
|
||||
@@ -368,7 +366,7 @@ final class MembersEditorTest extends TestCase
|
||||
);
|
||||
|
||||
$persistables = $editor->getPersistable();
|
||||
$this->assertEquals(1, count($persistables));
|
||||
$this->assertEquals(1, \count($persistables));
|
||||
|
||||
$membership2 = $persistables[0];
|
||||
$this->assertSame($household2, $membership2->getHousehold());
|
||||
@@ -391,7 +389,7 @@ final class MembersEditorTest extends TestCase
|
||||
|
||||
$factory = $this->buildMembersEditorFactory();
|
||||
$editor = $factory->createEditor($household1);
|
||||
$editor->addMovement(new DateTimeImmutable('today'), $person, $positionSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('today'), $person, $positionSharing);
|
||||
$editor->postMove();
|
||||
|
||||
self::assertContains($person, $household1->getCurrentPersons());
|
||||
@@ -410,7 +408,7 @@ final class MembersEditorTest extends TestCase
|
||||
);
|
||||
$editor = $factory->createEditor($household2);
|
||||
|
||||
$editor->addMovement(new DateTimeImmutable('today'), $person, $positionNotSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('today'), $person, $positionNotSharing);
|
||||
$editor->postMove();
|
||||
|
||||
// $household1 still contains $person
|
||||
@@ -442,7 +440,7 @@ final class MembersEditorTest extends TestCase
|
||||
|
||||
$factory = $this->buildMembersEditorFactory();
|
||||
$editor = $factory->createEditor($household1);
|
||||
$editor->addMovement(new DateTimeImmutable('1 year ago'), $person, $positionSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('1 year ago'), $person, $positionSharing);
|
||||
$editor->postMove();
|
||||
|
||||
self::assertContains($person, $household1->getCurrentPersons());
|
||||
@@ -461,7 +459,7 @@ final class MembersEditorTest extends TestCase
|
||||
);
|
||||
$editor = $factory->createEditor($household2);
|
||||
|
||||
$editor->addMovement(new DateTimeImmutable('yesterday'), $person, $positionNotSharing);
|
||||
$editor->addMovement(new \DateTimeImmutable('yesterday'), $person, $positionNotSharing);
|
||||
$editor->postMove();
|
||||
|
||||
// $household1 still contains $person
|
||||
@@ -494,7 +492,7 @@ final class MembersEditorTest extends TestCase
|
||||
// set into the first household
|
||||
$editor = $this->buildMembersEditorFactory()
|
||||
->createEditor($household1);
|
||||
$editor->addMovement(new DateTimeImmutable('1 year ago'), $person, $position);
|
||||
$editor->addMovement(new \DateTimeImmutable('1 year ago'), $person, $position);
|
||||
|
||||
// prepare for next move
|
||||
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
|
||||
@@ -507,7 +505,7 @@ final class MembersEditorTest extends TestCase
|
||||
);
|
||||
$editor = $factory->createEditor($household1);
|
||||
|
||||
$editor->addMovement(new DateTimeImmutable('now'), $person, $position2);
|
||||
$editor->addMovement(new \DateTimeImmutable('now'), $person, $position2);
|
||||
|
||||
$editor->postMove();
|
||||
}
|
||||
@@ -523,7 +521,7 @@ final class MembersEditorTest extends TestCase
|
||||
// set into the first household
|
||||
$editor = $this->buildMembersEditorFactory()
|
||||
->createEditor($household1);
|
||||
$editor->addMovement(new DateTimeImmutable('1 year ago'), $person, $position);
|
||||
$editor->addMovement(new \DateTimeImmutable('1 year ago'), $person, $position);
|
||||
|
||||
// perform now the movement
|
||||
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
|
||||
@@ -536,7 +534,7 @@ final class MembersEditorTest extends TestCase
|
||||
);
|
||||
$editor = $factory->createEditor($household2);
|
||||
|
||||
$editor->addMovement(new DateTimeImmutable('now'), $person, $position);
|
||||
$editor->addMovement(new \DateTimeImmutable('now'), $person, $position);
|
||||
|
||||
$editor->postMove();
|
||||
}
|
||||
@@ -557,14 +555,14 @@ final class MembersEditorTest extends TestCase
|
||||
);
|
||||
$editor = $factory->createEditor($household1);
|
||||
|
||||
$editor->addMovement(new DateTimeImmutable('now'), $person, $position);
|
||||
$editor->addMovement(new \DateTimeImmutable('now'), $person, $position);
|
||||
|
||||
$editor->postMove();
|
||||
}
|
||||
|
||||
private function buildMembersEditorFactory(
|
||||
?EventDispatcherInterface $eventDispatcher = null,
|
||||
?ValidatorInterface $validator = null
|
||||
EventDispatcherInterface $eventDispatcher = null,
|
||||
ValidatorInterface $validator = null
|
||||
) {
|
||||
if (null === $eventDispatcher) {
|
||||
$double = $this->getProphet()->prophesize();
|
||||
|
Reference in New Issue
Block a user