mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
Rename membership edition and add more fixtures
This commit is contained in:
parent
edc86af659
commit
ace3b1969e
@ -4,7 +4,7 @@ namespace Chill\PersonBundle\DataFixtures\ORM;
|
|||||||
|
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Entity\Household\Household;
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
use Chill\PersonBundle\Household\MoveMembersFactory;
|
use Chill\PersonBundle\Household\MembersEditorFactory;
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\Persistence\ObjectManager;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
@ -12,33 +12,53 @@ use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
|||||||
|
|
||||||
class LoadHousehold extends Fixture implements DependentFixtureInterface
|
class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||||
{
|
{
|
||||||
private MoveMembersFactory $movementFactory;
|
private MembersEditorFactory $editorFactory;
|
||||||
|
|
||||||
private EntityManagerInterface $em;
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
private CONST NUMBER_OF_HOUSEHOLD = 10;
|
private CONST NUMBER_OF_HOUSEHOLD = 10;
|
||||||
|
|
||||||
public function __construct(MoveMembersFactory $movementFactory, EntityManagerInterface $em)
|
public function __construct(MembersEditorFactory $editorFactory, EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
$this->movementFactory = $movementFactory;
|
$this->editorFactory = $editorFactory;
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load(ObjectManager $manager)
|
public function load(ObjectManager $manager)
|
||||||
{
|
{
|
||||||
|
// generate two times the participation. This will lead to
|
||||||
|
// some movement in participation (same people in two differents
|
||||||
|
// households)
|
||||||
|
|
||||||
$this->preparePersonIds();
|
$this->preparePersonIds();
|
||||||
|
|
||||||
|
$this->generateHousehold(
|
||||||
|
$manager,
|
||||||
|
\DateTimeImmutable::createFromFormat('Y-m-d', '2010-01-01')
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->preparePersonIds();
|
||||||
|
|
||||||
|
$this->generateHousehold(
|
||||||
|
$manager,
|
||||||
|
\DateTimeImmutable::createFromFormat('Y-m-d', '2015-01-01')
|
||||||
|
);
|
||||||
|
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generateHousehold(ObjectManager $manager, \DateTimeImmutable $startDate)
|
||||||
|
{
|
||||||
for ($i=0; $i < self::NUMBER_OF_HOUSEHOLD; $i++) {
|
for ($i=0; $i < self::NUMBER_OF_HOUSEHOLD; $i++) {
|
||||||
$household = new Household();
|
$household = new Household();
|
||||||
$manager->persist($household);
|
$manager->persist($household);
|
||||||
|
|
||||||
$movement = $this->movementFactory->createMovement($household);
|
$movement = $this->editorFactory->createEditor($household);
|
||||||
|
|
||||||
// load adults
|
// load adults
|
||||||
$k = 0;
|
$k = 0;
|
||||||
foreach ($this->getRandomPersons(1, 3) as $person) {
|
foreach ($this->getRandomPersons(1, 3) as $person) {
|
||||||
$date = \DateTimeImmutable::createFromFormat('Y-m-d', '2010-01-01')
|
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
||||||
->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
|
||||||
$position = $this->getReference(LoadHouseholdPosition::ADULT);
|
$position = $this->getReference(LoadHouseholdPosition::ADULT);
|
||||||
|
|
||||||
$movement->addMovement($date, $person, $position, $k === 0, "self generated");
|
$movement->addMovement($date, $person, $position, $k === 0, "self generated");
|
||||||
@ -47,21 +67,26 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
|||||||
|
|
||||||
// load children
|
// load children
|
||||||
foreach ($this->getRandomPersons(0, 3) as $person) {
|
foreach ($this->getRandomPersons(0, 3) as $person) {
|
||||||
$date = \DateTimeImmutable::createFromFormat('Y-m-d', '2010-01-01')
|
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
||||||
->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
|
||||||
$position = $this->getReference(LoadHouseholdPosition::CHILD);
|
$position = $this->getReference(LoadHouseholdPosition::CHILD);
|
||||||
|
|
||||||
$movement->addMovement($date, $person, $position, $k === 0, "self generated");
|
$movement->addMovement($date, $person, $position, $k === 0, "self generated");
|
||||||
$k++;
|
$k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load children out
|
||||||
|
foreach ($this->getRandomPersons(0, 2) as $person) {
|
||||||
|
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
||||||
|
$position = $this->getReference(LoadHouseholdPosition::CHILD_OUT);
|
||||||
|
|
||||||
|
$movement->addMovement($date, $person, $position, $k === 0, "self generated");
|
||||||
|
$k++;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($movement->getPersistable() as $obj) {
|
foreach ($movement->getPersistable() as $obj) {
|
||||||
print($obj->getStartDate()->format('Y-m-d'));
|
|
||||||
$manager->persist($obj);
|
$manager->persist($obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$manager->flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function preparePersonIds()
|
private function preparePersonIds()
|
||||||
|
@ -10,7 +10,7 @@ use Chill\PersonBundle\Entity\Person;
|
|||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
|
|
||||||
class MoveMembers
|
class MembersEditor
|
||||||
{
|
{
|
||||||
private ValidatorInterface $validator;
|
private ValidatorInterface $validator;
|
||||||
private Household $household;
|
private Household $household;
|
||||||
@ -18,18 +18,12 @@ class MoveMembers
|
|||||||
private array $persistables = [];
|
private array $persistables = [];
|
||||||
private array $memershipsAffected = [];
|
private array $memershipsAffected = [];
|
||||||
|
|
||||||
public function __construct(ValidatorInterface $validator)
|
public function __construct(ValidatorInterface $validator, Household $household)
|
||||||
{
|
{
|
||||||
$this->validation = $validator;
|
$this->validation = $validator;
|
||||||
|
$this->household = $household;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toHousehold(Household $household): self
|
|
||||||
{
|
|
||||||
$this->household = $household;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addMovement(\DateTimeInterface $date, Person $person, Position $position, ?bool $holder = false, ?string $comment = null): self
|
public function addMovement(\DateTimeInterface $date, Person $person, Position $position, ?bool $holder = false, ?string $comment = null): self
|
||||||
{
|
{
|
||||||
if (NULL === $this->household) {
|
if (NULL === $this->household) {
|
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Household;
|
||||||
|
|
||||||
|
use Chill\PersonBundle\Household\MembersEditor;
|
||||||
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
|
|
||||||
|
class MembersEditorFactory
|
||||||
|
{
|
||||||
|
public function __construct(ValidatorInterface $validator)
|
||||||
|
{
|
||||||
|
$this->validator = $validator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createEditor(Household $household): MembersEditor
|
||||||
|
{
|
||||||
|
return new MembersEditor($this->validator, $household);
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Household;
|
|
||||||
|
|
||||||
use Chill\PersonBundle\Household\MoveMembers;
|
|
||||||
use Chill\PersonBundle\Entity\Household\Household;
|
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
||||||
|
|
||||||
|
|
||||||
class MoveMembersFactory
|
|
||||||
{
|
|
||||||
public function __construct(ValidatorInterface $validator)
|
|
||||||
{
|
|
||||||
$this->validator = $validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createMovement(?Household $household): MoveMembers
|
|
||||||
{
|
|
||||||
$movement = new MoveMembers($this->validator);
|
|
||||||
|
|
||||||
if ($household) {
|
|
||||||
$movement->toHousehold($household);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $movement;
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,21 +5,21 @@ namespace Chill\PersonBundle\Tests\Household;
|
|||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Entity\Household\Household;
|
use Chill\PersonBundle\Entity\Household\Household;
|
||||||
use Chill\PersonBundle\Entity\Household\Position;
|
use Chill\PersonBundle\Entity\Household\Position;
|
||||||
use Chill\PersonBundle\Household\MoveMembersFactory;
|
use Chill\PersonBundle\Household\MembersEditorFactory;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
|
||||||
class MoveMembersTest extends TestCase
|
class MembersEditorTest extends TestCase
|
||||||
{
|
{
|
||||||
private MoveMembersFactory $factory;
|
private MembersEditorFactory $factory;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$validator = $this->createMock(ValidatorInterface::class);
|
$validator = $this->createMock(ValidatorInterface::class);
|
||||||
|
|
||||||
$this->factory = new MoveMembersFactory($validator);
|
$this->factory = new MembersEditorFactory($validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMovePersonWithSharedHousehold()
|
public function testMovePersonWithSharedHousehold()
|
||||||
@ -30,7 +30,7 @@ class MoveMembersTest extends TestCase
|
|||||||
;
|
;
|
||||||
$household1 = new Household();
|
$household1 = new Household();
|
||||||
$household2 = new Household();
|
$household2 = new Household();
|
||||||
$editor = $this->factory->createMovement($household1);
|
$editor = $this->factory->createEditor($household1);
|
||||||
|
|
||||||
$editor->addMovement(
|
$editor->addMovement(
|
||||||
\DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'),
|
\DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'),
|
||||||
@ -46,7 +46,7 @@ class MoveMembersTest extends TestCase
|
|||||||
|
|
||||||
// move to another household
|
// 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->createMovement($household2);
|
$editor = $this->factory->createEditor($household2);
|
||||||
$editor->addMovement(
|
$editor->addMovement(
|
||||||
$date,
|
$date,
|
||||||
$person,
|
$person,
|
||||||
@ -70,7 +70,7 @@ class MoveMembersTest extends TestCase
|
|||||||
;
|
;
|
||||||
$household1 = new Household();
|
$household1 = new Household();
|
||||||
$household2 = new Household();
|
$household2 = new Household();
|
||||||
$editor = $this->factory->createMovement($household1);
|
$editor = $this->factory->createEditor($household1);
|
||||||
|
|
||||||
$editor->addMovement(
|
$editor->addMovement(
|
||||||
\DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'),
|
\DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01'),
|
||||||
@ -86,7 +86,7 @@ class MoveMembersTest extends TestCase
|
|||||||
|
|
||||||
// move to another household
|
// 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->createMovement($household2);
|
$editor = $this->factory->createEditor($household2);
|
||||||
$editor->addMovement(
|
$editor->addMovement(
|
||||||
$date,
|
$date,
|
||||||
$person,
|
$person,
|
@ -1,3 +1,3 @@
|
|||||||
services:
|
services:
|
||||||
Chill\PersonBundle\Household\MoveMembersFactory:
|
Chill\PersonBundle\Household\MembersEditorFactory:
|
||||||
autowire: true
|
autowire: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user