From 63871c9ce49086e5c97075af957ccb63600f2809 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Thu, 10 May 2018 12:41:21 -0400 Subject: [PATCH] [Messenger] Make sure default receiver name is set before command configuration --- .../Command/ConsumeMessagesCommand.php | 4 +-- .../Command/ConsumeMessagesCommandTest.php | 36 +++++++++++++++++++ src/Symfony/Component/Messenger/composer.json | 1 + 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php diff --git a/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php b/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php index 62892c59f059e..e64d10f1953e7 100644 --- a/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php +++ b/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php @@ -41,12 +41,12 @@ class ConsumeMessagesCommand extends Command public function __construct(MessageBusInterface $bus, ContainerInterface $receiverLocator, LoggerInterface $logger = null, string $defaultReceiverName = null) { - parent::__construct(); - $this->bus = $bus; $this->receiverLocator = $receiverLocator; $this->logger = $logger; $this->defaultReceiverName = $defaultReceiverName; + + parent::__construct(); } /** diff --git a/src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php b/src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php new file mode 100644 index 0000000000000..4eca2423aa47c --- /dev/null +++ b/src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Messenger\Tests\Command; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\ServiceLocator; +use Symfony\Component\Messenger\Command\ConsumeMessagesCommand; +use Symfony\Component\Messenger\MessageBus; + +class ConsumeMessagesCommandTest extends TestCase +{ + public function testConfigurationWithDefaultReceiver() + { + $command = new ConsumeMessagesCommand($this->createMock(MessageBus::class), $this->createMock(ServiceLocator::class), null, 'messenger.transport.amqp'); + $inputArgument = $command->getDefinition()->getArgument('receiver'); + $this->assertFalse($inputArgument->isRequired()); + $this->assertSame('messenger.transport.amqp', $inputArgument->getDefault()); + } + + public function testConfigurationWithoutDefaultReceiver() + { + $command = new ConsumeMessagesCommand($this->createMock(MessageBus::class), $this->createMock(ServiceLocator::class)); + $inputArgument = $command->getDefinition()->getArgument('receiver'); + $this->assertTrue($inputArgument->isRequired()); + $this->assertNull($inputArgument->getDefault()); + } +} diff --git a/src/Symfony/Component/Messenger/composer.json b/src/Symfony/Component/Messenger/composer.json index 1767f4dab967e..adbd0e2a9f671 100644 --- a/src/Symfony/Component/Messenger/composer.json +++ b/src/Symfony/Component/Messenger/composer.json @@ -20,6 +20,7 @@ }, "require-dev": { "psr/log": "~1.0", + "symfony/console": "~3.4|~4.0", "symfony/dependency-injection": "~3.4.6|~4.0", "symfony/http-kernel": "~3.4|~4.0", "symfony/process": "~3.4|~4.0",