Skip to content

Commit

Permalink
Merge pull request #9 from driftphp/feature/update-command-name
Browse files Browse the repository at this point in the history
Fixed debug command name
  • Loading branch information
mmoreram authored Jan 22, 2020
2 parents c1ba5a5 + 78b7eab commit 1536a35
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Class CommandConsumer.
*/
class CommandConsumer extends Command
class CommandConsumerCommand extends Command
{
/**
* @var AsyncAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class BusDebugger.
* Class DebugCommandBusCommand.
*/
class BusDebugger extends Command
class DebugCommandBusCommand extends Command
{
protected static $defaultName = 'debug:command-bus';
/**
* @var CommandBus
*/
Expand Down
26 changes: 16 additions & 10 deletions DependencyInjection/CompilerPass/BusCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
use Drift\CommandBus\Bus\CommandBus;
use Drift\CommandBus\Bus\InlineCommandBus;
use Drift\CommandBus\Bus\QueryBus;
use Drift\CommandBus\Console\BusDebugger;
use Drift\CommandBus\Console\CommandConsumer;
use Drift\CommandBus\Console\CommandConsumerCommand;
use Drift\CommandBus\Console\DebugCommandBusCommand;
use Drift\CommandBus\Exception\InvalidMiddlewareException;
use Drift\CommandBus\Middleware\AsyncMiddleware;
use Drift\CommandBus\Middleware\HandlerMiddleware;
Expand Down Expand Up @@ -178,7 +178,9 @@ private function createQueryBus(ContainerBuilder $container)
false
),
]
))->addTag('preload')
))
->addTag('preload')
->setLazy(true)
);

$container->setAlias(QueryBus::class, 'drift.query_bus');
Expand All @@ -202,7 +204,9 @@ private function createCommandBus(
$asyncBus
),
]
))->addTag('preload')
))
->addTag('preload')
->setLazy(true)
);

$container->setAlias(CommandBus::class, 'drift.command_bus');
Expand All @@ -223,7 +227,9 @@ private function createInlineCommandBus(ContainerBuilder $container)
false
),
]
))->addTag('preload')
))
->addTag('preload')
->setLazy(true)
);

$container->setAlias(InlineCommandBus::class, 'drift.inline_command_bus');
Expand Down Expand Up @@ -339,7 +345,7 @@ private function createHandlersMap(
*/
private function createCommandConsumer(ContainerBuilder $container)
{
$consumer = new Definition(CommandConsumer::class, [
$consumer = new Definition(CommandConsumerCommand::class, [
new Reference(AsyncAdapter::class),
new Reference('drift.inline_command_bus'),
new Reference('reactphp.event_loop'),
Expand All @@ -349,7 +355,7 @@ private function createCommandConsumer(ContainerBuilder $container)
'command' => 'bus:consume-commands',
]);

$container->setDefinition(CommandConsumer::class, $consumer);
$container->setDefinition(CommandConsumerCommand::class, $consumer);
}

/**
Expand All @@ -359,17 +365,17 @@ private function createCommandConsumer(ContainerBuilder $container)
*/
private function createBusDebugger(ContainerBuilder $container)
{
$consumer = new Definition(BusDebugger::class, [
$consumer = new Definition(DebugCommandBusCommand::class, [
new Reference('drift.command_bus'),
new Reference('drift.inline_command_bus'),
new Reference('drift.query_bus'),
]);

$consumer->addTag('console.command', [
'command' => 'debug:bus',
'command' => 'debug:command-bus',
]);

$container->setDefinition(BusDebugger::class, $consumer);
$container->setDefinition(DebugCommandBusCommand::class, $consumer);
}

/**
Expand Down
85 changes: 85 additions & 0 deletions Tests/Console/CommandsListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/*
* This file is part of the DriftPHP Project
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <[email protected]>
*/

declare(strict_types=1);

namespace Drift\CommandBus\Tests\Console;

use Drift\AMQP\AMQPBundle;
use Drift\CommandBus\Tests\BusFunctionalTest;

/**
* Class CommandsListTest.
*/
class CommandsListTest extends BusFunctionalTest
{
/**
* Decorate bundles.
*
* @param array $bundles
*
* @return array
*/
protected static function decorateBundles(array $bundles): array
{
$bundles[] = AMQPBundle::class;

return $bundles;
}

/**
* Decorate configuration.
*
* @param array $configuration
*
* @return array
*/
protected static function decorateConfiguration(array $configuration): array
{
$configuration = parent::decorateConfiguration($configuration);

$configuration['amqp'] = [
'clients' => [
'amqp_1' => [
'host' => '127.0.0.99',
],
],
];

$configuration['command_bus'] = [
'command_bus' => [
'async_adapter' => [
'amqp' => [
'client' => 'amqp_1',
'queue' => 'commands',
],
],
],
];

return $configuration;
}

/**
* Test that simple commands list works as expected.
*/
public function testCommandsList()
{
$output = $this->runCommand([
'',
]);

$this->assertContains('debug:command-bus', $output);
$this->assertContains('bus:consume-commands', $output);
}
}

0 comments on commit 1536a35

Please sign in to comment.