mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add address to household in fixtures
This commit is contained in:
parent
e68a5405a1
commit
38bff2e42f
@ -4,12 +4,15 @@ namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\PersonBundle\Household\MembersEditorFactory;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
use Nelmio\Alice\Loader\NativeLoader;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
|
||||
|
||||
class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
{
|
||||
@ -57,7 +60,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
$household = new Household();
|
||||
$manager->persist($household);
|
||||
|
||||
$this->addAddressToHousehold($household, \DateTimeImmutable::createFrom($startDate), $manager);
|
||||
$this->addAddressToHousehold($household, clone $startDate, $manager);
|
||||
|
||||
$movement = $this->editorFactory->createEditor($household);
|
||||
|
||||
@ -107,11 +110,11 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
$i = 0;
|
||||
while ($i < $nb) {
|
||||
$address = $this->createAddress();
|
||||
$address->validFrom($date);
|
||||
$address->setValidFrom(\DateTime::createFromImmutable($date));
|
||||
|
||||
if (\random_int(0, 20) < 1) {
|
||||
$date = $date->add(new \DateInterval('P'.\random_int(8, 52).'W'));
|
||||
$address->validTo($date);
|
||||
$address->setValidTo(\DateTime::createFromImmutable($date));
|
||||
}
|
||||
|
||||
$household->addAddress($address);
|
||||
@ -122,7 +125,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function createAddress()
|
||||
private function createAddress(): Address
|
||||
{
|
||||
$objectSet = $this->loader->loadData([
|
||||
Address::class => [
|
||||
@ -134,7 +137,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
]
|
||||
]);
|
||||
|
||||
return $objectSet->getObjects()[0];
|
||||
return $objectSet->getObjects()['address1'];
|
||||
}
|
||||
|
||||
private function getPostalCode(): PostalCode
|
||||
|
Loading…
x
Reference in New Issue
Block a user