Skip to content
Merged
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
5 changes: 1 addition & 4 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Extension/DestinationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'));
}
Expand Down
37 changes: 28 additions & 9 deletions src/Console/Command/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.')
;
}

Expand All @@ -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 "<info>%s</info>" has been deleted.', $input->getArgument('connection')));
} else {
$destination->declare();
$output->writeln(sprintf('The destination "<info>%s</info>" has been deleted.', $name));
} else {
$destination->declare();

$output->writeln(sprintf('The destination "<info>%s</info>" has been declared.', $input->getArgument('connection')));
$output->writeln(sprintf('The destination "<info>%s</info>" has been declared.', $name));
}
}

return 0;
return self::SUCCESS;
}

/**
Expand All @@ -79,4 +83,19 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
{
$this->createAutocomplete($this->manager, $input, $suggestions);
}

/**
* @return iterable<string, DestinationInterface>
*/
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);
}
}
}
35 changes: 35 additions & 0 deletions tests/Console/Command/SetupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
*
*/
Expand Down Expand Up @@ -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
*/
Expand Down