Skip to content
Snippets Groups Projects
Commit c9ecf8c4 authored by Fabrice Gangler's avatar Fabrice Gangler :art:
Browse files

test: add organizations fixture

parent 672fa003
No related branches found
No related tags found
No related merge requests found
<?php
/*
* This file is part of the Comptoir-du-Libre software.
* <https://gitlab.adullact.net/Comptoir/comptoir-du-libre>
*
* Copyright (c) ADULLACT <https://adullact.org>
* Association des Développeurs et Utilisateurs de Logiciels Libres
* pour les Administrations et les Collectivités Territoriales
*
* Comptoir-du-Libre 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.
*
* You should have received a copy of the GNU Affero General Public License
* along with this software. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>.
*/
declare(strict_types=1);
namespace App\DataFixtures;
use App\Entity\Organization;
use App\Entity\OrganizationType;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class AppOrganizationFixtures extends Fixture
{
public const ORGANIZATION_TYPES = [
'public_sector', 'no_profit', 'company'
];
public const ORGANIZATIONS = [
[
'createdAt' => '2022-06-19 13:31:24',
'updatedAt' => '2022-07-25 14:22:05',
'type' => 'public_sector',
'name' => "Mairie d'Abbeville",
'slug' => 'mairie-d-abbeville',
],
[
'createdAt' => '2023-06-19 13:31:24',
'updatedAt' => '2023-07-25 14:22:05',
'type' => 'public_sector',
'name' => "Ville Montpellier (34)",
'slug' => 'ville-montpellier-34',
'website' => 'https://www.montpellier.fr',
'oldComptoirId' => 17,
],
];
public function load(ObjectManager $manager): void
{
$organizationTypes = [];
foreach (self::ORGANIZATION_TYPES as $type) {
$organizationType = new OrganizationType();
$organizationType->setName("$type");
$manager->persist($organizationType);
$manager->flush();
$organizationTypes["$type"] = $organizationType;
}
foreach (self::ORGANIZATIONS as $key => $data) {
$createdAt = new \DateTimeImmutable($data['createdAt']);
$updatedAt = new \DateTimeImmutable($data['updatedAt']);
$organization = new Organization();
$organization->setName($data['name']);
$organization->setSlug($data['slug']);
$organization->setCreatedAt($createdAt);
$organization->setUpdatedAt($updatedAt);
$organization->setType($organizationTypes[$data['type']]);
if (isset($data['website'])) {
$organization->setWebsite($data['website']);
}
if (isset($data['oldComptoirId'])) {
$organization->setOldComptoirId($data['oldComptoirId']);
}
$manager->persist($organization);
$manager->flush();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment