Skip to content

Commit 43fb8b0

Browse files
committed
Merge branch 'pr-452'
2 parents 18c7e4a + 7303dfb commit 43fb8b0

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

pkg/enqueue-bundle/DependencyInjection/EnqueueExtension.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Enqueue\Bundle\DependencyInjection;
44

55
use Enqueue\AsyncEventDispatcher\DependencyInjection\AsyncEventDispatcherExtension;
6+
use Enqueue\Client\CommandSubscriberInterface;
67
use Enqueue\Client\Producer;
8+
use Enqueue\Client\TopicSubscriberInterface;
79
use Enqueue\Client\TraceableProducer;
810
use Enqueue\Consumption\QueueConsumer;
911
use Enqueue\JobQueue\Job;
@@ -72,6 +74,8 @@ public function load(array $configs, ContainerBuilder $container)
7274
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
7375
$loader->load('services.yml');
7476

77+
$this->setupAutowiringForProcessors($container);
78+
7579
foreach ($config['transport'] as $name => $transportConfig) {
7680
$this->factories[$name]->createConnectionFactory($container, $transportConfig);
7781
$this->factories[$name]->createContext($container, $transportConfig);
@@ -220,4 +224,19 @@ private function registerJobQueueDoctrineEntityMapping(ContainerBuilder $contain
220224
}
221225
}
222226
}
227+
228+
private function setupAutowiringForProcessors(ContainerBuilder $container)
229+
{
230+
if (!method_exists($container, 'registerForAutoconfiguration')) {
231+
return;
232+
}
233+
234+
$container->registerForAutoconfiguration(TopicSubscriberInterface::class)
235+
->setPublic(true)
236+
->addTag('enqueue.client.processor');
237+
238+
$container->registerForAutoconfiguration(CommandSubscriberInterface::class)
239+
->setPublic(true)
240+
->addTag('enqueue.client.processor');
241+
}
223242
}

pkg/enqueue-bundle/Tests/Unit/DependencyInjection/EnqueueExtensionTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
use Enqueue\Bundle\DependencyInjection\EnqueueExtension;
77
use Enqueue\Bundle\Tests\Unit\Mocks\FooTransportFactory;
88
use Enqueue\Bundle\Tests\Unit\Mocks\TransportFactoryWithoutDriverFactory;
9+
use Enqueue\Client\CommandSubscriberInterface;
910
use Enqueue\Client\Producer;
1011
use Enqueue\Client\ProducerInterface;
12+
use Enqueue\Client\TopicSubscriberInterface;
1113
use Enqueue\Client\TraceableProducer;
1214
use Enqueue\Consumption\QueueConsumer;
1315
use Enqueue\JobQueue\JobRunner;
@@ -633,6 +635,31 @@ public function testShouldThrowIfPackageShouldBeInstalledToUseTransport()
633635
]], $container);
634636
}
635637

638+
public function testShouldLoadProcessAutoconfigureChildDefinition()
639+
{
640+
if (30300 >= Kernel::VERSION_ID) {
641+
$this->markTestSkipped('The autoconfigure feature is available since Symfony 3.3 version');
642+
}
643+
644+
$container = $this->getContainerBuilder(true);
645+
$extension = new EnqueueExtension();
646+
647+
$extension->load([[
648+
'client' => [],
649+
'transport' => [],
650+
]], $container);
651+
652+
$autoconfigured = $container->getAutoconfiguredInstanceof();
653+
654+
self::assertArrayHasKey(CommandSubscriberInterface::class, $autoconfigured);
655+
self::assertTrue($autoconfigured[CommandSubscriberInterface::class]->hasTag('enqueue.client.processor'));
656+
self::assertTrue($autoconfigured[CommandSubscriberInterface::class]->isPublic());
657+
658+
self::assertArrayHasKey(TopicSubscriberInterface::class, $autoconfigured);
659+
self::assertTrue($autoconfigured[TopicSubscriberInterface::class]->hasTag('enqueue.client.processor'));
660+
self::assertTrue($autoconfigured[TopicSubscriberInterface::class]->isPublic());
661+
}
662+
636663
/**
637664
* @param bool $debug
638665
*

pkg/sqs/SqsProducer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public function send(PsrDestination $destination, PsrMessage $message)
4242
InvalidMessageException::assertMessageInstanceOf($message, SqsMessage::class);
4343

4444
$body = $message->getBody();
45-
if (is_scalar($body) || null === $body) {
45+
if (is_scalar($body) && strlen($body) > 0) {
4646
$body = (string) $body;
4747
} else {
4848
throw new InvalidMessageException(sprintf(
49-
'The message body must be a scalar or null. Got: %s',
49+
'The message body must be a non-empty string. Got: %s',
5050
is_object($body) ? get_class($body) : gettype($body)
5151
));
5252
}

pkg/sqs/Tests/SqsProducerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testCouldBeConstructedWithRequiredArguments()
3131
public function testShouldThrowIfBodyOfInvalidType()
3232
{
3333
$this->expectException(InvalidMessageException::class);
34-
$this->expectExceptionMessage('The message body must be a scalar or null. Got: stdClass');
34+
$this->expectExceptionMessage('The message body must be a non-empty string. Got: stdClass');
3535

3636
$producer = new SqsProducer($this->createSqsContextMock());
3737

@@ -72,7 +72,7 @@ public function testShouldThrowIfSendMessageFailed()
7272
;
7373

7474
$destination = new SqsDestination('queue-name');
75-
$message = new SqsMessage();
75+
$message = new SqsMessage('foo');
7676

7777
$this->expectException(\RuntimeException::class);
7878
$this->expectExceptionMessage('Message was not sent');

0 commit comments

Comments
 (0)