diff --git a/src/Infrastructure/Symfony/Command/StorageAreaGenerateCommand.php b/src/Infrastructure/Symfony/Command/StorageAreaGenerateCommand.php new file mode 100644 index 000000000..905bcd7eb --- /dev/null +++ b/src/Infrastructure/Symfony/Command/StorageAreaGenerateCommand.php @@ -0,0 +1,103 @@ + $name) { + $row[$name] = $values[$index]; + } + + $rows[] = $row; + } + + return $rows; + } + + private function makePhp(array $rows): string + { + $lines = []; + + $columns = [ + 'uuid', + 'description', + 'administrator', + 'road_number', + 'from_point_number', + 'from_side', + 'from_abscissa', + 'to_point_number', + 'to_side', + 'to_abscissa', + 'geometry', + ]; + + $valuesList = []; + + foreach ($rows as $row) { + $values = [ + 'uuid' => 'uuid_generate_v4()', + 'description' => "''", + 'administrator' => "''", + 'road_number' => "''", + 'from_point_number' => "'10'", + 'from_side' => "'D'", + 'from_abscissa' => '0', + 'to_point_number' => "'11'", + 'to_side' => "'D'", + 'to_abscissa' => '0', + 'geometry' => "ST_MakePoint('0 1')", + ]; + + $valuesList[] = \sprintf(' (%s)', implode(', ', $values)); + } + + $statement = \sprintf( + 'INSERT INTO storage_area (%s) VALUES%s%s', + implode(', ', $columns), + PHP_EOL, + implode(\sprintf(',%s', PHP_EOL), $valuesList), + ); + + $lines[] = \sprintf('$this->addSql(\'%s\');', $statement); + + return implode(PHP_EOL, $lines); + } + + public function execute(InputInterface $input, OutputInterface $output): int + { + $csv = file_get_contents(\sprintf('%s/data/aires_de_stockage.csv', $this->projectDir)); + $rows = $this->parseCsvAssociative($csv); + $output->writeln($this->makePhp($rows)); + + return Command::SUCCESS; + } +} diff --git a/tests/Integration/Infrastructure/Symfony/Command/StorageAreaGenerateCommandTest.php b/tests/Integration/Infrastructure/Symfony/Command/StorageAreaGenerateCommandTest.php new file mode 100644 index 000000000..4decf0842 --- /dev/null +++ b/tests/Integration/Infrastructure/Symfony/Command/StorageAreaGenerateCommandTest.php @@ -0,0 +1,29 @@ +get(StorageAreaGenerateCommand::class); + $commandTester = new CommandTester($command); + + $commandTester->execute([]); + $commandTester->assertCommandIsSuccessful(); + + $this->assertEmpty($commandTester->getDisplay()); + } +}