From ea5204cbb3b6acdd609e57b187493d090a3a6ea1 Mon Sep 17 00:00:00 2001 From: sebprt Date: Mon, 22 Jan 2024 16:59:49 +0100 Subject: [PATCH 1/2] Made that the Remove and Update commands in the Cloud context can be used with several satellites in a single file --- src/Cloud/Console/Command/RemoveCommand.php | 20 ++++++++++++-------- src/Cloud/Console/Command/UpdateCommand.php | 20 ++++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/Cloud/Console/Command/RemoveCommand.php b/src/Cloud/Console/Command/RemoveCommand.php index 58da5a9f..bcea73ac 100644 --- a/src/Cloud/Console/Command/RemoveCommand.php +++ b/src/Cloud/Console/Command/RemoveCommand.php @@ -124,14 +124,18 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - $instance = match (true) { - \array_key_exists('pipeline', $configuration) => new Satellite\Cloud\Pipeline($context), - \array_key_exists('workflow', $configuration) => new Satellite\Cloud\Workflow($context), - default => throw new \RuntimeException('Invalid runtime satellite configuration.'), - }; - - foreach ($instance->remove($instance::fromApiWithCode($client, array_key_first($configuration['satellites']))->id()) as $command) { - $bus->push($command); + + foreach ($configuration['satellites'] as $code => $satellite) { + $satellite['code'] = $code; + $instance = match (true) { + \array_key_exists('pipeline', $satellite) => new Satellite\Cloud\Pipeline($context), + \array_key_exists('workflow', $satellite) => new Satellite\Cloud\Workflow($context), + default => throw new \RuntimeException('Invalid runtime satellite configuration.'), + }; + + foreach ($instance->remove($instance::fromApiWithCode($client, array_key_first($configuration['satellites']))->id()) as $command) { + $bus->push($command); + } } $bus->execute(); diff --git a/src/Cloud/Console/Command/UpdateCommand.php b/src/Cloud/Console/Command/UpdateCommand.php index e6128bb2..3bba6ad3 100644 --- a/src/Cloud/Console/Command/UpdateCommand.php +++ b/src/Cloud/Console/Command/UpdateCommand.php @@ -126,14 +126,18 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O } $context = new Satellite\Cloud\Context($client, $auth, $url); - $instance = match (true) { - \array_key_exists('pipeline', $configuration) => new Satellite\Cloud\Pipeline($context), - \array_key_exists('workflow', $configuration) => new Satellite\Cloud\Workflow($context), - default => throw new \RuntimeException('Invalid runtime satellite configuration.'), - }; - - foreach ($instance->update($instance::fromApiWithCode($client, array_key_first($configuration['satellites'])), $instance::fromLegacyConfiguration($configuration['satellite'])) as $command) { - $bus->push($command); + + foreach ($configuration['satellites'] as $code => $satellite) { + $satellite['code'] = $code; + $instance = match (true) { + \array_key_exists('pipeline', $satellite) => new Satellite\Cloud\Pipeline($context), + \array_key_exists('workflow', $satellite) => new Satellite\Cloud\Workflow($context), + default => throw new \RuntimeException('Invalid runtime satellite configuration.'), + }; + + foreach ($instance->update($instance::fromApiWithCode($client, array_key_first($configuration['satellites'])), $instance::fromLegacyConfiguration($configuration['satellite'])) as $command) { + $bus->push($command); + } } $bus->execute(); From 3bd74f8cb62cd8367fffc613719917912caf4c5b Mon Sep 17 00:00:00 2001 From: sebprt Date: Tue, 23 Jan 2024 09:40:35 +0100 Subject: [PATCH 2/2] Added test for Cloud commands --- .../Console/Command/CreateCommandTest.php | 51 +++++++++++++++++++ .../Console/Command/RemoveCommandTest.php | 10 ++++ .../Console/Command/UpdateCommandTest.php | 10 ++++ 3 files changed, 71 insertions(+) create mode 100644 tests/functional/Cloud/Console/Command/CreateCommandTest.php create mode 100644 tests/functional/Cloud/Console/Command/RemoveCommandTest.php create mode 100644 tests/functional/Cloud/Console/Command/UpdateCommandTest.php diff --git a/tests/functional/Cloud/Console/Command/CreateCommandTest.php b/tests/functional/Cloud/Console/Command/CreateCommandTest.php new file mode 100644 index 00000000..025ca72b --- /dev/null +++ b/tests/functional/Cloud/Console/Command/CreateCommandTest.php @@ -0,0 +1,51 @@ +add(new CreateCommand()); + + $command = $application->find('create'); + $commandTester = new CommandTester($command); + $commandTester->execute( + [ + 'config' => sys_get_temp_dir(), + ] + ); + + $output = $commandTester->getDisplay(); + $this->assertStringContainsString('Résultat attendu', $output); + + $this->assertSame(0, $commandTester->getStatusCode()); + } + + public function testCreateCommandWithMultipleSatellite(): void + { + $application = new Application(); + $application->add(new CreateCommand()); + + $command = $application->find('create'); + $commandTester = new CommandTester($command); + $commandTester->execute( + [ + 'config' => sys_get_temp_dir(), + ] + ); + + $output = $commandTester->getDisplay(); + $this->assertStringContainsString('Résultat attendu', $output); + + $this->assertSame(0, $commandTester->getStatusCode()); + } +} diff --git a/tests/functional/Cloud/Console/Command/RemoveCommandTest.php b/tests/functional/Cloud/Console/Command/RemoveCommandTest.php new file mode 100644 index 00000000..18b1d3a7 --- /dev/null +++ b/tests/functional/Cloud/Console/Command/RemoveCommandTest.php @@ -0,0 +1,10 @@ +