Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed Mar 22, 2023
1 parent 087fa68 commit 02e8a39
Show file tree
Hide file tree
Showing 11 changed files with 6,908 additions and 23 deletions.
2 changes: 1 addition & 1 deletion features/api/committees.feature
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Feature:

Scenario: As a user granted with local scope, I can get geo zone available for a new committee
Given I am logged with "[email protected]" via OAuth client "JeMengage Web" with scope "jemengage_admin"
And I send a "GET" request to "/api/v3/zone/autocomplete?scope=referent&q=Hauts&availableForCommittee=true"
And I send a "GET" request to "/api/v3/zone/autocomplete?scope=referent&q=Hauts de Flandre&availableForCommittee=true"
Then the response status code should be 200
And the response should be in JSON
And the JSON should be equal to:
Expand Down
27 changes: 27 additions & 0 deletions migrations/Version20230322154120.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20230322154120 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE geo_city DROP FOREIGN KEY FK_297C2D349D25CF90');
$this->addSql('ALTER TABLE
geo_city
ADD
CONSTRAINT FK_297C2D349D25CF90 FOREIGN KEY (replacement_id) REFERENCES geo_city (id) ON DELETE CASCADE');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE geo_city DROP FOREIGN KEY FK_297C2D349D25CF90');
$this->addSql('ALTER TABLE
geo_city
ADD
CONSTRAINT FK_297C2D349D25CF90 FOREIGN KEY (replacement_id) REFERENCES geo_city (id) ON UPDATE NO ACTION ON DELETE NO ACTION');
}
}
15 changes: 0 additions & 15 deletions src/DataFixtures/ORM/AbstractFixtures.php

This file was deleted.

13 changes: 7 additions & 6 deletions src/DataFixtures/ORM/LoadJecouteRegionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
use App\Entity\Geo\Zone;
use App\Entity\Jecoute\Region;
use App\Jecoute\RegionColorEnum;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Ramsey\Uuid\Uuid;

class LoadJecouteRegionData extends AbstractFixtures implements DependentFixtureInterface
class LoadJecouteRegionData extends Fixture implements DependentFixtureInterface
{
public const REGION_1_UUID = '88275043-adb5-463a-8a62-5248fe7aacbf';
public const REGION_2_UUID = 'c91391e9-4a08-4d14-8960-6c3508c1dddc';
Expand All @@ -20,9 +21,9 @@ public function load(ObjectManager $manager)
{
$manager->persist($this->createRegion(
self::REGION_1_UUID,
$this->getZoneEntity($manager, 269), // geo_region_28 - Normandie
LoadGeoZoneData::getZoneReference($manager, 'zone_region_28'), // Normandie
'Bienvenue en Normandie',
'Description de la normandie',
'Description de la Normandie',
RegionColorEnum::RED,
'region-logo.jpg',
'region-banner.jpg',
Expand All @@ -31,7 +32,7 @@ public function load(ObjectManager $manager)

$manager->persist($this->createRegion(
self::REGION_2_UUID,
$this->getZoneEntity($manager, 265), // geo_region_32 - Hauts-de-France
LoadGeoZoneData::getZoneReference($manager, 'zone_region_32'), // Hauts-de-France
'Bienvenue en Hauts-de-France',
'Description des Hauts-de-France',
RegionColorEnum::GREEN,
Expand All @@ -42,7 +43,7 @@ public function load(ObjectManager $manager)

$manager->persist($this->createRegion(
self::REGION_3_UUID,
$this->getZoneEntity($manager, 266), // geo_region_93 - Provence-Alpes-Côte d'Azur
LoadGeoZoneData::getZoneReference($manager, 'zone_region_93'), // Provence-Alpes-Côte d'Azur
'Bienvenue en PACA',
'Description PACA',
RegionColorEnum::BLUE,
Expand All @@ -51,7 +52,7 @@ public function load(ObjectManager $manager)

$manager->persist($this->createRegion(
self::REGION_4_UUID,
$this->getZoneEntity($manager, 81), // geo_country_FR - France
LoadGeoZoneData::getZoneReference($manager, 'zone_country_FR'), // France
'Campagne nationale',
'Description de la campagne nationale',
RegionColorEnum::PURPLE,
Expand Down
1 change: 1 addition & 0 deletions src/Entity/Geo/City.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class City implements ZoneableInterface
* @var City|null
*
* @ORM\ManyToOne(targetEntity="App\Entity\Geo\City")
* @ORM\JoinColumn(onDelete="CASCADE")
*/
private $replacement;

Expand Down
1 change: 0 additions & 1 deletion src/Normalizer/ItemNormalizerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ public function denormalize($data, $class, $format = null, array $context = [])

$context['api_denormalize'] = true;

# GOTO:
if ($this->resourceClassResolver->isResourceClass($class)) {
$newResourceClass = $this->resourceClassResolver->getResourceClass($objectToPopulate, $class);
if (!(new \ReflectionClass($newResourceClass))->isAbstract()) {
Expand Down
55 changes: 55 additions & 0 deletions zone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

use Doctrine\DBAL\DriverManager;
use League\Csv\Reader;
use League\Csv\Writer;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Finder\Finder;

require __DIR__.'/vendor/autoload.php';

$connectionParams = [
'url' => 'mysql://root:[email protected]:3306/enmarche?charset=utf8',
];

$conn = DriverManager::getConnection($connectionParams);

$csv = Reader::createFromPath(__DIR__.'/zone_uuid_migration2.csv')->setDelimiter(';')->setHeaderOffset(0);

$io = new SymfonyStyle(
new Symfony\Component\Console\Input\ArrayInput([]),
new Symfony\Component\Console\Output\ConsoleOutput(OutputInterface::VERBOSITY_VERY_VERBOSE)
);

$io->progressStart(count($csv));

//$zonesFromDb = $conn->executeQuery('SELECT concat(TYPE, \'_\', code) AS id, code, uuid FROM geo_zone')->fetchAllAssociativeIndexed();

$zones = [];
foreach ($csv as $row) {
$zones[] = $row;
$io->progressAdvance();
}

$finder = Finder::create()->in(__DIR__.'/features')->name('*.feature')->ignoreDotFiles(true);
$toUpdate = [];

$files = [];
foreach ($finder->files() as $file) {
$files[$file->getPathname()] = file_get_contents($file->getPathname());
}

foreach ($zones as $zone) {
foreach ($files as $filePath => $fileContent) {
if (str_contains($fileContent, $zone['old'])) {
$toUpdate[] = $zone;
file_put_contents($filePath, str_replace($zone['old'], $zone['new'], $fileContent));
}
}
}

dd($toUpdate);

//$writer = Writer::createFromPath(__DIR__.'/zone_to_update.csv', 'w')->setDelimiter(';');
//$writer->insertAll($toUpdate);
67 changes: 67 additions & 0 deletions zone_to_update.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
AF;e3ef6700-906e-11eb-a875-0242ac150002;943e2b28-872a-11eb-9419-42010a840019
ES;e3ef84ed-906e-11eb-a875-0242ac150002;943fb07b-872a-11eb-9419-42010a840019
ES;e3ef84ed-906e-11eb-a875-0242ac150002;943fb07b-872a-11eb-9419-42010a840019
FR;e3ef8883-906e-11eb-a875-0242ac150002;943fb3ac-872a-11eb-9419-42010a840019
CIRCO_FDE-06;e3efac36-906e-11eb-a875-0242ac150002;943fda85-872a-11eb-9419-42010a840019
CH;e3efcea1-906e-11eb-a875-0242ac150002;943ffff9-872a-11eb-9419-42010a840019
11;e3efe139-906e-11eb-a875-0242ac150002;9440131e-872a-11eb-9419-42010a840019
75;e3efe563-906e-11eb-a875-0242ac150002;944057ca-872a-11eb-9419-42010a840019
75;e3efe563-906e-11eb-a875-0242ac150002;944057ca-872a-11eb-9419-42010a840019
77;e3efe5c5-906e-11eb-a875-0242ac150002;94405a9c-872a-11eb-9419-42010a840019
77;e3efe5c5-906e-11eb-a875-0242ac150002;94405a9c-872a-11eb-9419-42010a840019
77;e3efe5c5-906e-11eb-a875-0242ac150002;94405a9c-872a-11eb-9419-42010a840019
77;e3efe5c5-906e-11eb-a875-0242ac150002;94405a9c-872a-11eb-9419-42010a840019
77;e3efe5c5-906e-11eb-a875-0242ac150002;94405a9c-872a-11eb-9419-42010a840019
92;e3efe6fd-906e-11eb-a875-0242ac150002;944062a9-872a-11eb-9419-42010a840019
92;e3efe6fd-906e-11eb-a875-0242ac150002;944062a9-872a-11eb-9419-42010a840019
92;e3efe6fd-906e-11eb-a875-0242ac150002;944062a9-872a-11eb-9419-42010a840019
92;e3efe6fd-906e-11eb-a875-0242ac150002;944062a9-872a-11eb-9419-42010a840019
92;e3efe6fd-906e-11eb-a875-0242ac150002;944062a9-872a-11eb-9419-42010a840019
92;e3efe6fd-906e-11eb-a875-0242ac150002;944062a9-872a-11eb-9419-42010a840019
92;e3efe6fd-906e-11eb-a875-0242ac150002;944062a9-872a-11eb-9419-42010a840019
92;e3efe6fd-906e-11eb-a875-0242ac150002;944062a9-872a-11eb-9419-42010a840019
92;e3efe6fd-906e-11eb-a875-0242ac150002;944062a9-872a-11eb-9419-42010a840019
92;e3efe6fd-906e-11eb-a875-0242ac150002;944062a9-872a-11eb-9419-42010a840019
94;e3efe7bf-906e-11eb-a875-0242ac150002;9440643f-872a-11eb-9419-42010a840019
76;e3efef5d-906e-11eb-a875-0242ac150002;94405a38-872a-11eb-9419-42010a840019
59;e3eff020-906e-11eb-a875-0242ac150002;9440518c-872a-11eb-9419-42010a840019
59;e3eff020-906e-11eb-a875-0242ac150002;9440518c-872a-11eb-9419-42010a840019
13;e3f01553-906e-11eb-a875-0242ac150002;94403ac2-872a-11eb-9419-42010a840019
75-1;e3f0bf9d-906e-11eb-a875-0242ac150002;94415793-872a-11eb-9419-42010a840019
75-1;e3f0bf9d-906e-11eb-a875-0242ac150002;94415793-872a-11eb-9419-42010a840019
75-1;e3f0bf9d-906e-11eb-a875-0242ac150002;94415793-872a-11eb-9419-42010a840019
75-1;e3f0bf9d-906e-11eb-a875-0242ac150002;94415793-872a-11eb-9419-42010a840019
75-2;e3f0bfff-906e-11eb-a875-0242ac150002;944157f5-872a-11eb-9419-42010a840019
92-11;e3f0ebd6-906e-11eb-a875-0242ac150002;94418bb1-872a-11eb-9419-42010a840019
7723;e3f15390-906e-11eb-a875-0242ac150002;94459aa3-872a-11eb-9419-42010a840019
9203;e3f154b1-906e-11eb-a875-0242ac150002;94463aee-872a-11eb-9419-42010a840019
200040954;e3f17cac-906e-11eb-a875-0242ac150002;94966e3d-872a-11eb-9419-42010a840019
200043321;e3f17e32-906e-11eb-a875-0242ac150002;94966a68-872a-11eb-9419-42010a840019
200055655;e3f180d7-906e-11eb-a875-0242ac150002;94970e20-872a-11eb-9419-42010a840019
200057958;e3f18139-906e-11eb-a875-0242ac150002;94970c96-872a-11eb-9419-42010a840019
200059228;e3f1828a-906e-11eb-a875-0242ac150002;94970d5a-872a-11eb-9419-42010a840019
200072130;e3f187e7-906e-11eb-a875-0242ac150002;94970ab1-872a-11eb-9419-42010a840019
200072346;e3f18848-906e-11eb-a875-0242ac150002;9497061e-872a-11eb-9419-42010a840019
200090504;e3f18a2c-906e-11eb-a875-0242ac150002;9497067f-872a-11eb-9419-42010a840019
245901038;e3f18d97-906e-11eb-a875-0242ac150002;94966e9d-872a-11eb-9419-42010a840019
247600505;e3f19169-906e-11eb-a875-0242ac150002;94970317-872a-11eb-9419-42010a840019
247700065;e3f197ca-906e-11eb-a875-0242ac150002;94970805-872a-11eb-9419-42010a840019
06004;e3f19d3c-906e-11eb-a875-0242ac150002;944aa68b-872a-11eb-9419-42010a840019
06088;e3f1a8e8-906e-11eb-a875-0242ac150002;944ac8ee-872a-11eb-9419-42010a840019
13080;e3f1cb08-906e-11eb-a875-0242ac150002;94500a09-872a-11eb-9419-42010a840019
13098;e3f1e343-906e-11eb-a875-0242ac150002;94501105-872a-11eb-9419-42010a840019
59350;e3f21338-906e-11eb-a875-0242ac150002;9477b1d8-872a-11eb-9419-42010a840019
59350;e3f21338-906e-11eb-a875-0242ac150002;9477b1d8-872a-11eb-9419-42010a840019
59350;e3f21338-906e-11eb-a875-0242ac150002;9477b1d8-872a-11eb-9419-42010a840019
59350;e3f21338-906e-11eb-a875-0242ac150002;9477b1d8-872a-11eb-9419-42010a840019
75056;e3f274b8-906e-11eb-a875-0242ac150002;94869992-872a-11eb-9419-42010a840019
76495;e3f28b24-906e-11eb-a875-0242ac150002;94878f83-872a-11eb-9419-42010a840019
77079;e3f29811-906e-11eb-a875-0242ac150002;94884d7a-872a-11eb-9419-42010a840019
77210;e3f2a3e7-906e-11eb-a875-0242ac150002;948886c7-872a-11eb-9419-42010a840019
77430;e3f2b860-906e-11eb-a875-0242ac150002;9488f5dd-872a-11eb-9419-42010a840019
77514;e3f2c010-906e-11eb-a875-0242ac150002;94891a56-872a-11eb-9419-42010a840019
92024;e3f2c4a0-906e-11eb-a875-0242ac150002;94938c58-872a-11eb-9419-42010a840019
92032;e3f2c5ec-906e-11eb-a875-0242ac150002;94938d80-872a-11eb-9419-42010a840019
92060;e3f2cb17-906e-11eb-a875-0242ac150002;949393bc-872a-11eb-9419-42010a840019
CONS_030-1;e3f33a66-906e-11eb-a875-0242ac150002;94989c6b-872a-11eb-9419-42010a840019
CONS_030-2;e3f33ac7-906e-11eb-a875-0242ac150002;94989cd0-872a-11eb-9419-42010a840019
Loading

0 comments on commit 02e8a39

Please sign in to comment.