diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml
index 373dd3b..bae188b 100644
--- a/.github/workflows/php.yml
+++ b/.github/workflows/php.yml
@@ -86,14 +86,11 @@ jobs:
with:
timezoneLinux: "Europe/Paris"
- - name: Install gearman PECL
- run: sudo apt-get install -y libgearman-dev
-
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
- extensions: json, gearman, redis
+ extensions: json, redis
ini-values: date.timezone=Europe/Paris
- name: Install dependencies
diff --git a/src/Console/Command/Extension/DestinationExtension.php b/src/Console/Command/Extension/DestinationExtension.php
index 90df919..f007bdd 100644
--- a/src/Console/Command/Extension/DestinationExtension.php
+++ b/src/Console/Command/Extension/DestinationExtension.php
@@ -44,9 +44,9 @@ public function createDestination(DestinationManager $destinationManager, InputI
*
* @param InputDefinition $definition
*/
- public function configureDestinationOptions(InputDefinition $definition)
+ public function configureDestinationOptions(InputDefinition $definition, bool $connectionIsRequired = true)
{
- $definition->addArgument(new InputArgument('connection', InputArgument::REQUIRED, 'The name of connection'));
+ $definition->addArgument(new InputArgument('connection', $connectionIsRequired ? InputArgument::REQUIRED : InputArgument::OPTIONAL, 'The name of connection'));
$definition->addOption(new InputOption('queue', null, InputOption::VALUE_REQUIRED, 'The queues to listen on. can be separated by comma (only for reading).'));
$definition->addOption(new InputOption('topic', null, InputOption::VALUE_REQUIRED, 'The topic to subscribe.'));
}
diff --git a/src/Console/Command/SetupCommand.php b/src/Console/Command/SetupCommand.php
index 321b52b..b047b90 100644
--- a/src/Console/Command/SetupCommand.php
+++ b/src/Console/Command/SetupCommand.php
@@ -3,6 +3,7 @@
namespace Bdf\Queue\Console\Command;
use Bdf\Queue\Console\Command\Extension\DestinationExtension;
+use Bdf\Queue\Destination\DestinationInterface;
use Bdf\Queue\Destination\DestinationManager;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
@@ -44,11 +45,12 @@ public function __construct(DestinationManager $manager)
*/
protected function configure(): void
{
- $this->configureDestinationOptions($this->getDefinition());
+ $this->configureDestinationOptions($this->getDefinition(), false);
$this
->setDescription('Declare or delete a queue from a connection.')
->addOption('drop', null, InputOption::VALUE_NONE, 'Delete the queue from connection.')
+ ->addOption('all', null, InputOption::VALUE_NONE, 'Apply on all declared destinations.')
;
}
@@ -57,19 +59,21 @@ protected function configure(): void
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
- $destination = $this->createDestination($this->manager, $input);
+ $isDrop = $input->getOption('drop');
- if ($input->getOption('drop')) {
- $destination->destroy();
+ foreach ($this->destinations($input) as $name => $destination) {
+ if ($isDrop) {
+ $destination->destroy();
- $output->writeln(sprintf('The destination "%s" has been deleted.', $input->getArgument('connection')));
- } else {
- $destination->declare();
+ $output->writeln(sprintf('The destination "%s" has been deleted.', $name));
+ } else {
+ $destination->declare();
- $output->writeln(sprintf('The destination "%s" has been declared.', $input->getArgument('connection')));
+ $output->writeln(sprintf('The destination "%s" has been declared.', $name));
+ }
}
- return 0;
+ return self::SUCCESS;
}
/**
@@ -79,4 +83,19 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
{
$this->createAutocomplete($this->manager, $input, $suggestions);
}
+
+ /**
+ * @return iterable
+ */
+ private function destinations(InputInterface $input): iterable
+ {
+ if (!$input->getOption('all')) {
+ yield $input->getArgument('connection') => $this->createDestination($this->manager, $input);
+ return;
+ }
+
+ foreach ($this->manager->destinationNames() as $name) {
+ yield $name => $this->manager->create($name);
+ }
+ }
}
diff --git a/tests/Console/Command/SetupCommandTest.php b/tests/Console/Command/SetupCommandTest.php
index f738d9c..906b6df 100644
--- a/tests/Console/Command/SetupCommandTest.php
+++ b/tests/Console/Command/SetupCommandTest.php
@@ -79,6 +79,22 @@ public function test_declare_with_destination()
$this->assertArrayHasKey('bar', $this->connection->storage()->queues);
}
+ /**
+ *
+ */
+ public function test_declare_all()
+ {
+ $command = new SetupCommand($this->manager);
+ $tester = new CommandTester($command);
+
+ $tester->execute([
+ '--all' => true,
+ ]);
+
+ $this->assertMatchesRegularExpression('/^The destination "foo" has been declared/', $tester->getDisplay());
+ $this->assertArrayHasKey('bar', $this->connection->storage()->queues);
+ }
+
/**
*
*/
@@ -116,6 +132,25 @@ public function test_drop_queue()
$this->assertArrayNotHasKey('bar', $this->connection->storage()->queues);
}
+ /**
+ *
+ */
+ public function test_drop_all()
+ {
+ $this->connection->storage()->queues['bar'] = [];
+
+ $command = new SetupCommand($this->manager);
+ $tester = new CommandTester($command);
+
+ $tester->execute([
+ '--drop' => true,
+ '--all' => true,
+ ]);
+
+ $this->assertMatchesRegularExpression('/^The destination "foo" has been deleted/', $tester->getDisplay());
+ $this->assertArrayNotHasKey('bar', $this->connection->storage()->queues);
+ }
+
/**
* @dataProvider provideCompletionSuggestions
*/