Skip to content

Commit 9fdad5b

Browse files
authored
Merge pull request #694 from php-enqueue/fix-async-command-event-pkgs
Fix async command\event pkgs
2 parents 8c81a0a + f3fec66 commit 9fdad5b

File tree

10 files changed

+49
-92
lines changed

10 files changed

+49
-92
lines changed

pkg/async-command/DependencyInjection/AsyncCommandExtension.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22

33
namespace Enqueue\AsyncCommand\DependencyInjection;
44

5+
use Enqueue\AsyncCommand\Commands;
56
use Enqueue\AsyncCommand\RunCommandProcessor;
6-
use Symfony\Component\Config\FileLocator;
77
use Symfony\Component\DependencyInjection\ContainerBuilder;
88
use Symfony\Component\DependencyInjection\Extension\Extension;
9-
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
109

1110
class AsyncCommandExtension extends Extension
1211
{
13-
/**
14-
* {@inheritdoc}
15-
*/
1612
public function load(array $configs, ContainerBuilder $container)
1713
{
18-
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
19-
$loader->load('services.yml');
20-
21-
$service = $container->register('enqueue.async_command.run_command_processor', RunCommandProcessor::class)
22-
->addArgument('%kernel.project_dir%')
23-
;
24-
2514
foreach ($configs['clients'] as $client) {
26-
$service->addTag('enqueue.command_subscriber', ['client' => $client]);
15+
$id = sprintf('enqueue.async_command.%s.run_command_processor', $client);
16+
$container->register($id, RunCommandProcessor::class)
17+
->addArgument('%kernel.project_dir%')
18+
->addTag('enqueue.processor', [
19+
'client' => $client,
20+
'command' => Commands::RUN_COMMAND,
21+
'queue' => Commands::RUN_COMMAND,
22+
'queue_prefixed' => false,
23+
'exclusive' => true,
24+
])
25+
->addTag('enqueue.transport.processor')
26+
;
2727
}
2828
}
2929
}

pkg/async-command/Resources/config/services.yml

-7
This file was deleted.

pkg/async-command/RunCommandProcessor.php

+1-12
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
namespace Enqueue\AsyncCommand;
44

5-
use Enqueue\Client\CommandSubscriberInterface;
65
use Enqueue\Consumption\Result;
76
use Interop\Queue\Context;
87
use Interop\Queue\Message;
98
use Interop\Queue\Processor;
109
use Symfony\Component\Process\PhpExecutableFinder;
1110
use Symfony\Component\Process\Process;
1211

13-
final class RunCommandProcessor implements Processor, CommandSubscriberInterface
12+
final class RunCommandProcessor implements Processor
1413
{
1514
/**
1615
* @var string
@@ -42,16 +41,6 @@ public function process(Message $message, Context $context): Result
4241
return Result::ack();
4342
}
4443

45-
public static function getSubscribedCommand(): array
46-
{
47-
return [
48-
'command' => Commands::RUN_COMMAND,
49-
'queue' => Commands::RUN_COMMAND,
50-
'prefix_queue' => false,
51-
'exclusive' => true,
52-
];
53-
}
54-
5544
/**
5645
* @return string
5746
*/

pkg/async-command/Tests/RunCommandProcessorTest.php

-21
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Enqueue\AsyncCommand\Tests;
44

5-
use Enqueue\AsyncCommand\Commands;
65
use Enqueue\AsyncCommand\RunCommandProcessor;
7-
use Enqueue\Client\CommandSubscriberInterface;
86
use Interop\Queue\Processor;
97
use PHPUnit\Framework\TestCase;
108

@@ -17,13 +15,6 @@ public function testShouldImplementProcessorInterface()
1715
$this->assertTrue($rc->implementsInterface(Processor::class));
1816
}
1917

20-
public function testShouldImplementCommandSubscriberInterfaceInterface()
21-
{
22-
$rc = new \ReflectionClass(RunCommandProcessor::class);
23-
24-
$this->assertTrue($rc->implementsInterface(CommandSubscriberInterface::class));
25-
}
26-
2718
public function testShouldBeFinal()
2819
{
2920
$rc = new \ReflectionClass(RunCommandProcessor::class);
@@ -37,16 +28,4 @@ public function testCouldBeConstructedWithProjectDirAsFirstArgument()
3728

3829
$this->assertAttributeSame('aProjectDir', 'projectDir', $processor);
3930
}
40-
41-
public function testShouldSubscribeOnRunCommand()
42-
{
43-
$subscription = RunCommandProcessor::getSubscribedCommand();
44-
45-
$this->assertSame([
46-
'command' => Commands::RUN_COMMAND,
47-
'queue' => Commands::RUN_COMMAND,
48-
'prefix_queue' => false,
49-
'exclusive' => true,
50-
], $subscription);
51-
}
5231
}

pkg/async-event-dispatcher/AsyncProcessor.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
namespace Enqueue\AsyncEventDispatcher;
44

5-
use Enqueue\Client\CommandSubscriberInterface;
65
use Enqueue\Consumption\Result;
76
use Interop\Queue\Context;
87
use Interop\Queue\Message;
98
use Interop\Queue\Processor;
109
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1110

12-
class AsyncProcessor implements Processor, CommandSubscriberInterface
11+
class AsyncProcessor implements Processor
1312
{
1413
/**
1514
* @var Registry
@@ -51,9 +50,4 @@ public function process(Message $message, Context $context)
5150

5251
return self::ACK;
5352
}
54-
55-
public static function getSubscribedCommand()
56-
{
57-
return Commands::DISPATCH_ASYNC_EVENTS;
58-
}
5953
}

pkg/async-event-dispatcher/DependencyInjection/AsyncEventDispatcherExtension.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
namespace Enqueue\AsyncEventDispatcher\DependencyInjection;
44

5+
use Enqueue\AsyncEventDispatcher\AsyncProcessor;
6+
use Enqueue\AsyncEventDispatcher\Commands;
57
use Symfony\Component\Config\FileLocator;
68
use Symfony\Component\DependencyInjection\Alias;
79
use Symfony\Component\DependencyInjection\ContainerBuilder;
810
use Symfony\Component\DependencyInjection\Extension\Extension;
911
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
12+
use Symfony\Component\DependencyInjection\Reference;
1013

1114
class AsyncEventDispatcherExtension extends Extension
1215
{
13-
/**
14-
* {@inheritdoc}
15-
*/
1616
public function load(array $configs, ContainerBuilder $container)
1717
{
1818
$config = $this->processConfiguration(new Configuration(), $configs);
@@ -21,5 +21,17 @@ public function load(array $configs, ContainerBuilder $container)
2121

2222
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2323
$loader->load('services.yml');
24+
25+
$container->register('enqueue.events.async_processor', AsyncProcessor::class)
26+
->addArgument(new Reference('enqueue.events.registry'))
27+
->addArgument(new Reference('enqueue.events.event_dispatcher'))
28+
->addTag('enqueue.processor', [
29+
'command' => Commands::DISPATCH_ASYNC_EVENTS,
30+
'queue' => '%enqueue_events_queue%',
31+
'queue_prefixed' => false,
32+
'exclusive' => true,
33+
])
34+
->addTag('enqueue.transport.processor')
35+
;
2436
}
2537
}

pkg/async-event-dispatcher/Resources/config/services.yml

-14
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@ services:
2525
- '@event_dispatcher'
2626
- '@enqueue.events.async_listener'
2727

28-
enqueue.events.async_processor:
29-
class: 'Enqueue\AsyncEventDispatcher\AsyncProcessor'
30-
public: public
31-
arguments:
32-
- '@enqueue.events.registry'
33-
- '@enqueue.events.event_dispatcher'
34-
tags:
35-
-
36-
name: 'enqueue.processor'
37-
command: 'symfony.dispatch_async_events'
38-
queue: '%enqueue_events_queue%'
39-
queue_prefixed: false
40-
exclusive: true
41-
4228
enqueue.events.php_serializer_event_transofrmer:
4329
class: 'Enqueue\AsyncEventDispatcher\PhpSerializerEventTransformer'
4430
public: public

pkg/enqueue-bundle/Tests/Functional/App/config/config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ services:
7575
alias: 'enqueue.client.routes_command'
7676
public: true
7777

78+
test.enqueue.events.async_processor:
79+
alias: 'enqueue.events.async_processor'
80+
public: true
81+
7882
test_async_listener:
7983
class: 'Enqueue\Bundle\Tests\Functional\App\TestAsyncListener'
8084
public: true

pkg/enqueue-bundle/Tests/Functional/Events/AsyncProcessorTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public function setUp()
3333
public function testCouldBeGetFromContainerAsService()
3434
{
3535
/** @var AsyncProcessor $processor */
36-
$processor = static::$container->get('enqueue.events.async_processor');
36+
$processor = static::$container->get('test.enqueue.events.async_processor');
3737

3838
$this->assertInstanceOf(AsyncProcessor::class, $processor);
3939
}
4040

4141
public function testShouldRejectIfMessageDoesNotContainEventNameProperty()
4242
{
4343
/** @var AsyncProcessor $processor */
44-
$processor = static::$container->get('enqueue.events.async_processor');
44+
$processor = static::$container->get('test.enqueue.events.async_processor');
4545

4646
$message = new NullMessage();
4747

@@ -51,7 +51,7 @@ public function testShouldRejectIfMessageDoesNotContainEventNameProperty()
5151
public function testShouldRejectIfMessageDoesNotContainTransformerNameProperty()
5252
{
5353
/** @var AsyncProcessor $processor */
54-
$processor = static::$container->get('enqueue.events.async_processor');
54+
$processor = static::$container->get('test.enqueue.events.async_processor');
5555

5656
$message = new NullMessage();
5757
$message->setProperty('event_name', 'anEventName');
@@ -62,7 +62,7 @@ public function testShouldRejectIfMessageDoesNotContainTransformerNameProperty()
6262
public function testShouldCallRealListener()
6363
{
6464
/** @var AsyncProcessor $processor */
65-
$processor = static::$container->get('enqueue.events.async_processor');
65+
$processor = static::$container->get('test.enqueue.events.async_processor');
6666

6767
$message = new NullMessage();
6868
$message->setProperty('event_name', 'test_async');
@@ -93,7 +93,7 @@ public function testShouldCallRealListener()
9393
public function testShouldCallRealSubscriber()
9494
{
9595
/** @var AsyncProcessor $processor */
96-
$processor = static::$container->get('enqueue.events.async_processor');
96+
$processor = static::$container->get('test.enqueue.events.async_processor');
9797

9898
$message = new NullMessage();
9999
$message->setProperty('event_name', 'test_async_subscriber');

pkg/enqueue-bundle/Tests/Functional/RoutesCommandTest.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public function testShouldDisplayRegisteredTopics()
2525
$tester = new CommandTester($command);
2626
$tester->execute([]);
2727

28-
$expected = <<<'OUTPUT'
29-
| topic | theTopic | default (prefixed) | test_topic_subscriber_processor | (hidden) |
30-
OUTPUT;
31-
3228
$this->assertSame(0, $tester->getStatusCode());
33-
$this->assertContains($expected, $tester->getDisplay());
29+
$this->assertContains('| topic', $tester->getDisplay());
30+
$this->assertContains('| theTopic', $tester->getDisplay());
31+
$this->assertContains('| default (prefixed)', $tester->getDisplay());
32+
$this->assertContains('| test_topic_subscriber_processor', $tester->getDisplay());
33+
$this->assertContains('| (hidden)', $tester->getDisplay());
3434
}
3535

3636
public function testShouldDisplayCommands()
@@ -41,11 +41,11 @@ public function testShouldDisplayCommands()
4141
$tester = new CommandTester($command);
4242
$tester->execute([]);
4343

44-
$expected = <<<'OUTPUT'
45-
| command | theCommand | default (prefixed) | test_command_subscriber_processor | (hidden) |
46-
OUTPUT;
47-
4844
$this->assertSame(0, $tester->getStatusCode());
49-
$this->assertContains($expected, $tester->getDisplay());
45+
$this->assertContains('| command', $tester->getDisplay());
46+
$this->assertContains('| theCommand', $tester->getDisplay());
47+
$this->assertContains('| test_command_subscriber_processor', $tester->getDisplay());
48+
$this->assertContains('| default (prefixed)', $tester->getDisplay());
49+
$this->assertContains('| (hidden)', $tester->getDisplay());
5050
}
5151
}

0 commit comments

Comments
 (0)