Skip to content

Commit 764ec22

Browse files
authored
Merge pull request #502 from php-enqueue/remove-old-symfony-support
Remove support of old Symfony versions.
2 parents 5f44d13 + 6e77edd commit 764ec22

14 files changed

+20
-196
lines changed

Diff for: docs/async_event_dispatcher/quick_tour.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $eventQueue = $context->createQueue('symfony_events');
3939

4040
$registry = new SimpleRegistry(
4141
['the_event' => 'default'],
42-
['default' => new PhpSerializerEventTransformer($context, true)]
42+
['default' => new PhpSerializerEventTransformer($context)]
4343
);
4444

4545
$asyncListener = new AsyncListener($context, $registry, $eventQueue);

Diff for: pkg/async-event-dispatcher/AsyncProcessor.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AsyncProcessor implements PsrProcessor
1616
private $registry;
1717

1818
/**
19-
* @var AsyncEventDispatcher|OldAsyncEventDispatcher
19+
* @var AsyncEventDispatcher
2020
*/
2121
private $dispatcher;
2222

@@ -28,11 +28,10 @@ public function __construct(Registry $registry, EventDispatcherInterface $dispat
2828
{
2929
$this->registry = $registry;
3030

31-
if (false == ($dispatcher instanceof AsyncEventDispatcher || $dispatcher instanceof OldAsyncEventDispatcher)) {
31+
if (false == $dispatcher instanceof AsyncEventDispatcher) {
3232
throw new \InvalidArgumentException(sprintf(
33-
'The dispatcher argument must be either instance of "%s" or "%s" but got "%s"',
33+
'The dispatcher argument must be instance of "%s" but got "%s"',
3434
AsyncEventDispatcher::class,
35-
OldAsyncEventDispatcher::class,
3635
get_class($dispatcher)
3736
));
3837
}

Diff for: pkg/async-event-dispatcher/DependencyInjection/AsyncEventDispatcherExtension.php

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

33
namespace Enqueue\AsyncEventDispatcher\DependencyInjection;
44

5-
use Enqueue\AsyncEventDispatcher\OldAsyncEventDispatcher;
65
use Symfony\Component\Config\FileLocator;
76
use Symfony\Component\DependencyInjection\Alias;
87
use Symfony\Component\DependencyInjection\ContainerBuilder;
9-
use Symfony\Component\DependencyInjection\Definition;
108
use Symfony\Component\DependencyInjection\Extension\Extension;
119
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
12-
use Symfony\Component\DependencyInjection\Reference;
13-
use Symfony\Component\HttpKernel\Kernel;
1410

1511
class AsyncEventDispatcherExtension extends Extension
1612
{
@@ -25,13 +21,5 @@ public function load(array $configs, ContainerBuilder $container)
2521

2622
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2723
$loader->load('services.yml');
28-
29-
if (version_compare(Kernel::VERSION, '3.3', '<')) {
30-
$container->setDefinition('enqueue.events.event_dispatcher', new Definition(OldAsyncEventDispatcher::class, [
31-
new Reference('service_container'),
32-
new Reference('event_dispatcher'),
33-
new Reference('enqueue.events.async_listener'),
34-
]));
35-
}
3624
}
3725
}

Diff for: pkg/async-event-dispatcher/OldAsyncEventDispatcher.php

-61
This file was deleted.

Diff for: pkg/async-event-dispatcher/PhpSerializerEventTransformer.php

+1-29
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Interop\Queue\PsrContext;
66
use Interop\Queue\PsrMessage;
77
use Symfony\Component\EventDispatcher\Event;
8-
use Symfony\Component\HttpKernel\Kernel;
98

109
class PhpSerializerEventTransformer implements EventTransformer
1110
{
@@ -14,28 +13,19 @@ class PhpSerializerEventTransformer implements EventTransformer
1413
*/
1514
private $context;
1615

17-
/**
18-
* @var bool
19-
*/
20-
private $skipSymfonyVersionCheck;
21-
2216
/**
2317
* @param PsrContext $context
24-
* @param bool $skipSymfonyVersionCheck It is useful when async dispatcher is used without Kernel. So there is no way to check the version.
2518
*/
26-
public function __construct(PsrContext $context, $skipSymfonyVersionCheck = false)
19+
public function __construct(PsrContext $context)
2720
{
2821
$this->context = $context;
29-
$this->skipSymfonyVersionCheck = $skipSymfonyVersionCheck;
3022
}
3123

3224
/**
3325
* {@inheritdoc}
3426
*/
3527
public function toMessage($eventName, Event $event = null)
3628
{
37-
$this->assertSymfony30OrHigher();
38-
3929
return $this->context->createMessage(serialize($event));
4030
}
4131

@@ -44,24 +34,6 @@ public function toMessage($eventName, Event $event = null)
4434
*/
4535
public function toEvent($eventName, PsrMessage $message)
4636
{
47-
$this->assertSymfony30OrHigher();
48-
4937
return unserialize($message->getBody());
5038
}
51-
52-
private function assertSymfony30OrHigher()
53-
{
54-
if ($this->skipSymfonyVersionCheck) {
55-
return;
56-
}
57-
58-
if (version_compare(Kernel::VERSION, '3.0', '<')) {
59-
throw new \LogicException(
60-
'This transformer does not work on Symfony prior 3.0. '.
61-
'The event contains eventDispatcher and therefor could not be serialized. '.
62-
'You have to register a transformer for every async event. '.
63-
'Read the doc: https://github.com/php-enqueue/enqueue-dev/blob/master/docs/bundle/async_events.md#event-transformer'
64-
);
65-
}
66-
}
6739
}

Diff for: pkg/async-event-dispatcher/Tests/PhpSerializerEventTransformerTest.php

-37
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Interop\Queue\PsrMessage;
1111
use PHPUnit\Framework\TestCase;
1212
use Symfony\Component\EventDispatcher\GenericEvent;
13-
use Symfony\Component\HttpKernel\Kernel;
1413

1514
class PhpSerializerEventTransformerTest extends TestCase
1615
{
@@ -28,10 +27,6 @@ public function testCouldBeConstructedWithoutAnyArguments()
2827

2928
public function testShouldReturnMessageWithPhpSerializedEventAsBodyOnToMessage()
3029
{
31-
if (version_compare(Kernel::VERSION, '3.0', '<')) {
32-
$this->markTestSkipped('This functionality only works on Symfony 3.0 or higher');
33-
}
34-
3530
$transformer = new PhpSerializerEventTransformer($this->createContextStub());
3631

3732
$event = new GenericEvent('theSubject');
@@ -45,10 +40,6 @@ public function testShouldReturnMessageWithPhpSerializedEventAsBodyOnToMessage()
4540

4641
public function testShouldReturnEventUnserializedFromMessageBodyOnToEvent()
4742
{
48-
if (version_compare(Kernel::VERSION, '3.0', '<')) {
49-
$this->markTestSkipped('This functionality only works on Symfony 3.0 or higher');
50-
}
51-
5243
$message = new NullMessage();
5344
$message->setBody(serialize(new GenericEvent('theSubject')));
5445

@@ -60,34 +51,6 @@ public function testShouldReturnEventUnserializedFromMessageBodyOnToEvent()
6051
$this->assertEquals('theSubject', $event->getSubject());
6152
}
6253

63-
public function testThrowNotSupportedExceptionOnSymfonyPrior30OnToMessage()
64-
{
65-
if (version_compare(Kernel::VERSION, '3.0', '>=')) {
66-
$this->markTestSkipped('This functionality only works on Symfony 3.0 or higher');
67-
}
68-
69-
$this->expectException(\LogicException::class);
70-
$this->expectExceptionMessage('This transformer does not work on Symfony prior 3.0.');
71-
72-
$transformer = new PhpSerializerEventTransformer($this->createContextStub());
73-
74-
$transformer->toMessage(new GenericEvent());
75-
}
76-
77-
public function testThrowNotSupportedExceptionOnSymfonyPrior30OnToEvent()
78-
{
79-
if (version_compare(Kernel::VERSION, '3.0', '>=')) {
80-
$this->markTestSkipped('This functionality only works on Symfony 3.0 or higher');
81-
}
82-
83-
$this->expectException(\LogicException::class);
84-
$this->expectExceptionMessage('This transformer does not work on Symfony prior 3.0.');
85-
86-
$transformer = new PhpSerializerEventTransformer($this->createContextStub());
87-
88-
$transformer->toEvent('anEvent', new NullMessage());
89-
}
90-
9154
/**
9255
* @return \PHPUnit_Framework_MockObject_MockObject|PsrContext
9356
*/

Diff for: pkg/enqueue-bundle/Tests/Functional/Events/AsyncListenerTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ public function testShouldSendMessageIfDispatchedFromInsideListener()
8282
/** @var EventDispatcherInterface $dispatcher */
8383
$dispatcher = static::$container->get('event_dispatcher');
8484

85-
$dispatcher->addListener('foo', function (Event $event, $eventName, EventDispatcherInterface $dispatcher) {
85+
$eventName = 'an_event_'.uniqid();
86+
$dispatcher->addListener($eventName, function (Event $event, $eventName, EventDispatcherInterface $dispatcher) {
8687
$dispatcher->dispatch('test_async', new GenericEvent('theSubject', ['fooArg' => 'fooVal']));
8788
});
8889

89-
$dispatcher->dispatch('foo');
90+
$dispatcher->dispatch($eventName);
9091

9192
/** @var TraceableProducer $producer */
9293
$producer = static::$container->get('enqueue.producer');

Diff for: pkg/enqueue-bundle/Tests/Functional/Events/AsyncProcessorTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public function setUp()
2626
$asyncListener = static::$container->get('enqueue.events.async_listener');
2727

2828
$asyncListener->resetSyncMode();
29+
static::$container->get('test_async_subscriber')->calls = [];
30+
static::$container->get('test_async_listener')->calls = [];
2931
}
3032

3133
public function testCouldBeGetFromContainerAsService()

Diff for: pkg/enqueue-bundle/Tests/Functional/Events/AsyncSubscriberTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ public function testShouldSendMessageIfDispatchedFromInsideListener()
8282
/** @var EventDispatcherInterface $dispatcher */
8383
$dispatcher = static::$container->get('event_dispatcher');
8484

85-
$dispatcher->addListener('foo', function (Event $event, $eventName, EventDispatcherInterface $dispatcher) {
85+
$eventName = 'anEvent'.uniqid();
86+
$dispatcher->addListener($eventName, function (Event $event, $eventName, EventDispatcherInterface $dispatcher) {
8687
$dispatcher->dispatch('test_async_subscriber', new GenericEvent('theSubject', ['fooArg' => 'fooVal']));
8788
});
8889

89-
$dispatcher->dispatch('foo');
90+
$dispatcher->dispatch($eventName);
9091

9192
/** @var TraceableProducer $producer */
9293
$producer = static::$container->get('enqueue.producer');

Diff for: pkg/enqueue-bundle/Tests/Functional/QueuesCommandTest.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Enqueue\Client\RouterProcessor;
66
use Enqueue\Symfony\Client\Meta\QueuesCommand;
77
use Symfony\Component\Console\Tester\CommandTester;
8-
use Symfony\Component\HttpKernel\Kernel;
98

109
/**
1110
* @group functional
@@ -30,15 +29,7 @@ public function testShouldDisplayRegisteredQueues()
3029

3130
$this->assertContains(' default ', $display);
3231
$this->assertContains('enqueue.app.default', $display);
33-
34-
$displayId = RouterProcessor::class;
35-
if (30300 > Kernel::VERSION_ID) {
36-
// Symfony 3.2 and below make service identifiers lowercase, so we do the same.
37-
// To be removed when dropping support for Symfony < 3.3.
38-
$displayId = strtolower($displayId);
39-
}
40-
41-
$this->assertContains($displayId, $display);
32+
$this->assertContains(RouterProcessor::class, $display);
4233
}
4334

4435
public function testShouldDisplayRegisteredCommand()

Diff for: pkg/enqueue-bundle/Tests/Functional/TopicsCommandTest.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Enqueue\Client\RouterProcessor;
77
use Enqueue\Symfony\Client\Meta\TopicsCommand;
88
use Symfony\Component\Console\Tester\CommandTester;
9-
use Symfony\Component\HttpKernel\Kernel;
109

1110
/**
1211
* @group functional
@@ -30,15 +29,7 @@ public function testShouldDisplayRegisteredTopics()
3029
$display = $tester->getDisplay();
3130

3231
$this->assertContains('__router__', $display);
33-
34-
$displayId = RouterProcessor::class;
35-
if (30300 > Kernel::VERSION_ID) {
36-
// Symfony 3.2 and below make service identifiers lowercase, so we do the same.
37-
// To be removed when dropping support for Symfony < 3.3.
38-
$displayId = strtolower($displayId);
39-
}
40-
41-
$this->assertContains($displayId, $display);
32+
$this->assertContains(RouterProcessor::class, $display);
4233
}
4334

4435
public function testShouldDisplayCommands()

Diff for: pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,11 @@ public function provideEnqueueConfigs()
9393
],
9494
]];
9595

96-
// Symfony 2.x does not such env syntax
97-
if (version_compare(Kernel::VERSION, '3.2', '>=')) {
98-
yield 'default_dsn_as_env' => [[
99-
'transport' => [
100-
'default' => '%env(AMQP_DSN)%',
101-
],
102-
]];
103-
}
96+
yield 'default_dsn_as_env' => [[
97+
'transport' => [
98+
'default' => '%env(AMQP_DSN)%',
99+
],
100+
]];
104101

105102
yield 'default_dbal_as_dsn' => [[
106103
'transport' => [

0 commit comments

Comments
 (0)