Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3374d2f

Browse files
Merge pull request #965 from TiMESPLiNTER/feat/add-header-support-for-produce-command
Add header support for Symfony's produce command
2 parents 6a0a586 + 288e90e commit 3374d2f

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

‎pkg/enqueue/Symfony/Client/ProduceCommand.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Enqueue\Symfony\Client;
44

5+
use Enqueue\Client\Message;
56
use Enqueue\Client\ProducerInterface;
67
use Psr\Container\ContainerInterface;
78
use Psr\Container\NotFoundExceptionInterface;
@@ -44,6 +45,7 @@ protected function configure(): void
4445
$this
4546
->setDescription('Sends an event to the topic')
4647
->addArgument('message', InputArgument::REQUIRED, 'A message')
48+
->addOption('header', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'The message headers')
4749
->addOption('client', 'c', InputOption::VALUE_OPTIONAL, 'The client to consume messages from.', $this->defaultClient)
4850
->addOption('topic', null, InputOption::VALUE_OPTIONAL, 'The topic to send a message to')
4951
->addOption('command', null, InputOption::VALUE_OPTIONAL, 'The command to send a message to')
@@ -55,6 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
5557
$topic = $input->getOption('topic');
5658
$command = $input->getOption('command');
5759
$message = $input->getArgument('message');
60+
$headers = (array) $input->getOption('header');
5861
$client = $input->getOption('client');
5962

6063
if ($topic && $command) {
@@ -68,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
6871
}
6972

7073
if ($topic) {
71-
$producer->sendEvent($topic, $message);
74+
$producer->sendEvent($topic, newMessage($message, [], $headers));
7275

7376
$output->writeln('An event is sent');
7477
} elseif ($command) {

‎pkg/enqueue/Tests/Symfony/Client/ProduceCommandTest.php‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Enqueue\Tests\Symfony\Client;
44

5+
use Enqueue\Client\Message;
56
use Enqueue\Client\ProducerInterface;
67
use Enqueue\Container\Container;
78
use Enqueue\Symfony\Client\ProduceCommand;
@@ -42,10 +43,11 @@ public function testShouldHaveExpectedOptions()
4243
$command = new ProduceCommand($this->createMock(ContainerInterface::class), 'default');
4344

4445
$options = $command->getDefinition()->getOptions();
45-
$this->assertCount(3, $options);
46+
$this->assertCount(4, $options);
4647
$this->assertArrayHasKey('client', $options);
4748
$this->assertArrayHasKey('topic', $options);
4849
$this->assertArrayHasKey('command', $options);
50+
$this->assertArrayHasKey('header', $options);
4951
}
5052

5153
public function testShouldHaveExpectedAttributes()
@@ -112,11 +114,14 @@ public function testThrowIfBothTopicAndCommandOptionsAreSet()
112114

113115
public function testShouldSendEventToDefaultTransport()
114116
{
117+
$header = 'Content-Type: text/plain';
118+
$payload = 'theMessage';
119+
115120
$producerMock = $this->createProducerMock();
116121
$producerMock
117122
->expects($this->once())
118123
->method('sendEvent')
119-
->with('theTopic', 'theMessage')
124+
->with('theTopic', newMessage($payload, [], [$header]))
120125
;
121126
$producerMock
122127
->expects($this->never())
@@ -129,7 +134,8 @@ public function testShouldSendEventToDefaultTransport()
129134

130135
$tester = new CommandTester($command);
131136
$tester->execute([
132-
'message' => 'theMessage',
137+
'message' => $payload,
138+
'--header' => $header,
133139
'--topic' => 'theTopic',
134140
]);
135141
}
@@ -160,6 +166,9 @@ public function testShouldSendCommandToDefaultTransport()
160166

161167
public function testShouldSendEventToFooTransport()
162168
{
169+
$header = 'Content-Type: text/plain';
170+
$payload = 'theMessage';
171+
163172
$defaultProducerMock = $this->createProducerMock();
164173
$defaultProducerMock
165174
->expects($this->never())
@@ -174,7 +183,7 @@ public function testShouldSendEventToFooTransport()
174183
$fooProducerMock
175184
->expects($this->once())
176185
->method('sendEvent')
177-
->with('theTopic', 'theMessage')
186+
->with('theTopic', newMessage($payload, [], [$header]))
178187
;
179188
$fooProducerMock
180189
->expects($this->never())
@@ -188,7 +197,8 @@ public function testShouldSendEventToFooTransport()
188197

189198
$tester = new CommandTester($command);
190199
$tester->execute([
191-
'message' => 'theMessage',
200+
'message' => $payload,
201+
'--header' => $header,
192202
'--topic' => 'theTopic',
193203
'--client' => 'foo',
194204
]);

‎pkg/enqueue/Tests/Symfony/Client/SimpleProduceCommandTest.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ public function testShouldHaveExpectedOptions()
4040
$command = new SimpleProduceCommand($this->createProducerMock());
4141

4242
$options = $command->getDefinition()->getOptions();
43-
$this->assertCount(3, $options);
43+
$this->assertCount(4, $options);
4444
$this->assertArrayHasKey('client', $options);
4545
$this->assertArrayHasKey('topic', $options);
4646
$this->assertArrayHasKey('command', $options);
47+
$this->assertArrayHasKey('header', $options);
4748
}
4849

4950
public function testShouldHaveExpectedAttributes()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /