From 70b6c66540ea2b06fc6ee95a9cc21a18c34f002d Mon Sep 17 00:00:00 2001 From: Vincent QUATREVIEUX Date: Mon, 24 Mar 2025 15:47:17 +0100 Subject: [PATCH 1/3] feat: allow to setup all queues using queue:setup --all (#FRAM-190) --- .../Extension/DestinationExtension.php | 4 +- src/Console/Command/SetupCommand.php | 37 ++++++++++++++----- tests/Console/Command/SetupCommandTest.php | 35 ++++++++++++++++++ 3 files changed, 65 insertions(+), 11 deletions(-) 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 */ From c77087524e3bd8cd653212875219b9c5110c8ba7 Mon Sep 17 00:00:00 2001 From: Vincent QUATREVIEUX Date: Mon, 24 Mar 2025 16:33:40 +0100 Subject: [PATCH 2/3] ci: run code coverage on PHP 8.0 --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 373dd3b..11ed94a 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -92,7 +92,7 @@ jobs: - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.0 extensions: json, gearman, redis ini-values: date.timezone=Europe/Paris From bfabe542e21e0642ee215f62d732ac0feaaefa0c Mon Sep 17 00:00:00 2001 From: Vincent QUATREVIEUX Date: Mon, 24 Mar 2025 16:36:54 +0100 Subject: [PATCH 3/3] ci: remove gearman on coverage tests --- .github/workflows/php.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 11ed94a..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: 8.0 - extensions: json, gearman, redis + php-version: 7.4 + extensions: json, redis ini-values: date.timezone=Europe/Paris - name: Install dependencies