Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made that the Remove and Update commands in the Cloud context can be used with several satellites in a single file #152

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/Cloud/Console/Command/RemoveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 12 additions & 8 deletions src/Cloud/Console/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
51 changes: 51 additions & 0 deletions tests/functional/Cloud/Console/Command/CreateCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace functional\Cloud\Console\Command;

use Kiboko\Component\Satellite\Cloud\Console\Command\CreateCommand;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

class CreateCommandTest extends TestCase
{
public function testCreateCommandWithOneSatellite(): 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne comprend pas ce que ce test fait.

Est-ce que tu peux plutôt :

  • utiliser la commande en direct, pas besoin de passer par l'application complète
  • Injecter un client HTTP de mock et vérifiee que les requêtes soit conforme à tes attentes.


$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());
}
}
10 changes: 10 additions & 0 deletions tests/functional/Cloud/Console/Command/RemoveCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace functional\Cloud\Console\Command;

class RemoveCommandTest
{

}
10 changes: 10 additions & 0 deletions tests/functional/Cloud/Console/Command/UpdateCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace functional\Cloud\Console\Command;

class UpdateCommandTest
{

}
Loading