mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add tests for moving houshold
This commit is contained in:
parent
87ba68971c
commit
edc86af659
103
src/Bundle/ChillPersonBundle/Tests/Household/MoveMembersTest.php
Normal file
103
src/Bundle/ChillPersonBundle/Tests/Household/MoveMembersTest.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Household;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
use Chill\PersonBundle\Household\MoveMembersFactory;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
||||
class MoveMembersTest extends TestCase
|
||||
{
|
||||
private MoveMembersFactory $factory;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$validator = $this->createMock(ValidatorInterface::class);
|
||||
|
||||
$this->factory = new MoveMembersFactory($validator);
|
||||
}
|
||||
|
||||
public function testMovePersonWithSharedHousehold()
|
||||
{
|
||||
$person = new Person();
|
||||
$position = (new Position())
|
||||
->setShareHousehold(true)
|
||||
;
|
||||
$household1 = new Household();
|
||||
$household2 = new Household();
|
||||
$editor = $this->factory->createMovement($household1);
|
||||
|
||||
$editor->addMovement(
|
||||
\DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'),
|
||||
$person,
|
||||
$position);
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $person->getHouseholdParticipations());
|
||||
$this->assertEquals(1, $person->getHouseholdParticipations()->count());
|
||||
|
||||
$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');
|
||||
$editor = $this->factory->createMovement($household2);
|
||||
$editor->addMovement(
|
||||
$date,
|
||||
$person,
|
||||
$position);
|
||||
|
||||
$this->assertEquals(2, $person->getHouseholdParticipations()->count());
|
||||
|
||||
$membership2 = $person->getHouseholdParticipations()->last();
|
||||
$this->assertSame($household2, $membership2->getHousehold());
|
||||
$this->assertNull($membership2->getEndDate());
|
||||
$this->assertNotNull($membership1->getEndDate(),
|
||||
"assert that the membership1 is closed");
|
||||
$this->assertEquals($date, $membership1->getEndDate());
|
||||
}
|
||||
|
||||
public function testMovePersonWithoutSharedHousehold()
|
||||
{
|
||||
$person = new Person();
|
||||
$position = (new Position())
|
||||
->setShareHousehold(false)
|
||||
;
|
||||
$household1 = new Household();
|
||||
$household2 = new Household();
|
||||
$editor = $this->factory->createMovement($household1);
|
||||
|
||||
$editor->addMovement(
|
||||
\DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'),
|
||||
$person,
|
||||
$position);
|
||||
|
||||
$this->assertInstanceOf(Collection::class, $person->getHouseholdParticipations());
|
||||
$this->assertEquals(1, $person->getHouseholdParticipations()->count());
|
||||
|
||||
$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');
|
||||
$editor = $this->factory->createMovement($household2);
|
||||
$editor->addMovement(
|
||||
$date,
|
||||
$person,
|
||||
$position);
|
||||
|
||||
$this->assertEquals(2, $person->getHouseholdParticipations()->count());
|
||||
|
||||
$membership2 = $person->getHouseholdParticipations()->last();
|
||||
$this->assertNull($membership2->getEndDate());
|
||||
$this->assertSame($household2, $membership2->getHousehold());
|
||||
$this->assertNull($membership1->getEndDate(),
|
||||
"assert that the membership1 is not closed");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user