Skip to content

Commit 2b13f33

Browse files
ycerutosroze
authored andcommitted
[Messenger] Make sure default receiver name is set before command configuration
1 parent ba8b68e commit 2b13f33

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

Command/ConsumeMessagesCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ class ConsumeMessagesCommand extends Command
4141

4242
public function __construct(MessageBusInterface $bus, ContainerInterface $receiverLocator, LoggerInterface $logger = null, string $defaultReceiverName = null)
4343
{
44-
parent::__construct();
45-
4644
$this->bus = $bus;
4745
$this->receiverLocator = $receiverLocator;
4846
$this->logger = $logger;
4947
$this->defaultReceiverName = $defaultReceiverName;
48+
49+
parent::__construct();
5050
}
5151

5252
/**
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Messenger\Tests\Command;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\ServiceLocator;
16+
use Symfony\Component\Messenger\Command\ConsumeMessagesCommand;
17+
use Symfony\Component\Messenger\MessageBus;
18+
19+
class ConsumeMessagesCommandTest extends TestCase
20+
{
21+
public function testConfigurationWithDefaultReceiver()
22+
{
23+
$command = new ConsumeMessagesCommand($this->createMock(MessageBus::class), $this->createMock(ServiceLocator::class), null, 'messenger.transport.amqp');
24+
$inputArgument = $command->getDefinition()->getArgument('receiver');
25+
$this->assertFalse($inputArgument->isRequired());
26+
$this->assertSame('messenger.transport.amqp', $inputArgument->getDefault());
27+
}
28+
29+
public function testConfigurationWithoutDefaultReceiver()
30+
{
31+
$command = new ConsumeMessagesCommand($this->createMock(MessageBus::class), $this->createMock(ServiceLocator::class));
32+
$inputArgument = $command->getDefinition()->getArgument('receiver');
33+
$this->assertTrue($inputArgument->isRequired());
34+
$this->assertNull($inputArgument->getDefault());
35+
}
36+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"require-dev": {
2222
"psr/log": "~1.0",
23+
"symfony/console": "~3.4|~4.0",
2324
"symfony/dependency-injection": "~3.4.6|~4.0",
2425
"symfony/http-kernel": "~3.4|~4.0",
2526
"symfony/process": "~3.4|~4.0",

0 commit comments

Comments
 (0)