Skip to content

Remove support of old Symfony versions. #502

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/async_event_dispatcher/quick_tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $eventQueue = $context->createQueue('symfony_events');

$registry = new SimpleRegistry(
['the_event' => 'default'],
['default' => new PhpSerializerEventTransformer($context, true)]
['default' => new PhpSerializerEventTransformer($context)]
);

$asyncListener = new AsyncListener($context, $registry, $eventQueue);
Expand Down
7 changes: 3 additions & 4 deletions pkg/async-event-dispatcher/AsyncProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AsyncProcessor implements PsrProcessor
private $registry;

/**
* @var AsyncEventDispatcher|OldAsyncEventDispatcher
* @var AsyncEventDispatcher
*/
private $dispatcher;

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

if (false == ($dispatcher instanceof AsyncEventDispatcher || $dispatcher instanceof OldAsyncEventDispatcher)) {
if (false == $dispatcher instanceof AsyncEventDispatcher) {
throw new \InvalidArgumentException(sprintf(
'The dispatcher argument must be either instance of "%s" or "%s" but got "%s"',
'The dispatcher argument must be instance of "%s" but got "%s"',
AsyncEventDispatcher::class,
OldAsyncEventDispatcher::class,
get_class($dispatcher)
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

namespace Enqueue\AsyncEventDispatcher\DependencyInjection;

use Enqueue\AsyncEventDispatcher\OldAsyncEventDispatcher;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Kernel;

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

$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');

if (version_compare(Kernel::VERSION, '3.3', '<')) {
$container->setDefinition('enqueue.events.event_dispatcher', new Definition(OldAsyncEventDispatcher::class, [
new Reference('service_container'),
new Reference('event_dispatcher'),
new Reference('enqueue.events.async_listener'),
]));
}
}
}
61 changes: 0 additions & 61 deletions pkg/async-event-dispatcher/OldAsyncEventDispatcher.php

This file was deleted.

30 changes: 1 addition & 29 deletions pkg/async-event-dispatcher/PhpSerializerEventTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Interop\Queue\PsrContext;
use Interop\Queue\PsrMessage;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpKernel\Kernel;

class PhpSerializerEventTransformer implements EventTransformer
{
Expand All @@ -14,28 +13,19 @@ class PhpSerializerEventTransformer implements EventTransformer
*/
private $context;

/**
* @var bool
*/
private $skipSymfonyVersionCheck;

/**
* @param PsrContext $context
* @param bool $skipSymfonyVersionCheck It is useful when async dispatcher is used without Kernel. So there is no way to check the version.
*/
public function __construct(PsrContext $context, $skipSymfonyVersionCheck = false)
public function __construct(PsrContext $context)
{
$this->context = $context;
$this->skipSymfonyVersionCheck = $skipSymfonyVersionCheck;
}

/**
* {@inheritdoc}
*/
public function toMessage($eventName, Event $event = null)
{
$this->assertSymfony30OrHigher();

return $this->context->createMessage(serialize($event));
}

Expand All @@ -44,24 +34,6 @@ public function toMessage($eventName, Event $event = null)
*/
public function toEvent($eventName, PsrMessage $message)
{
$this->assertSymfony30OrHigher();

return unserialize($message->getBody());
}

private function assertSymfony30OrHigher()
{
if ($this->skipSymfonyVersionCheck) {
return;
}

if (version_compare(Kernel::VERSION, '3.0', '<')) {
throw new \LogicException(
'This transformer does not work on Symfony prior 3.0. '.
'The event contains eventDispatcher and therefor could not be serialized. '.
'You have to register a transformer for every async event. '.
'Read the doc: https://github.com/php-enqueue/enqueue-dev/blob/master/docs/bundle/async_events.md#event-transformer'
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Interop\Queue\PsrMessage;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\HttpKernel\Kernel;

class PhpSerializerEventTransformerTest extends TestCase
{
Expand All @@ -28,10 +27,6 @@ public function testCouldBeConstructedWithoutAnyArguments()

public function testShouldReturnMessageWithPhpSerializedEventAsBodyOnToMessage()
{
if (version_compare(Kernel::VERSION, '3.0', '<')) {
$this->markTestSkipped('This functionality only works on Symfony 3.0 or higher');
}

$transformer = new PhpSerializerEventTransformer($this->createContextStub());

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

public function testShouldReturnEventUnserializedFromMessageBodyOnToEvent()
{
if (version_compare(Kernel::VERSION, '3.0', '<')) {
$this->markTestSkipped('This functionality only works on Symfony 3.0 or higher');
}

$message = new NullMessage();
$message->setBody(serialize(new GenericEvent('theSubject')));

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

public function testThrowNotSupportedExceptionOnSymfonyPrior30OnToMessage()
{
if (version_compare(Kernel::VERSION, '3.0', '>=')) {
$this->markTestSkipped('This functionality only works on Symfony 3.0 or higher');
}

$this->expectException(\LogicException::class);
$this->expectExceptionMessage('This transformer does not work on Symfony prior 3.0.');

$transformer = new PhpSerializerEventTransformer($this->createContextStub());

$transformer->toMessage(new GenericEvent());
}

public function testThrowNotSupportedExceptionOnSymfonyPrior30OnToEvent()
{
if (version_compare(Kernel::VERSION, '3.0', '>=')) {
$this->markTestSkipped('This functionality only works on Symfony 3.0 or higher');
}

$this->expectException(\LogicException::class);
$this->expectExceptionMessage('This transformer does not work on Symfony prior 3.0.');

$transformer = new PhpSerializerEventTransformer($this->createContextStub());

$transformer->toEvent('anEvent', new NullMessage());
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|PsrContext
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ public function testShouldSendMessageIfDispatchedFromInsideListener()
/** @var EventDispatcherInterface $dispatcher */
$dispatcher = static::$container->get('event_dispatcher');

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

$dispatcher->dispatch('foo');
$dispatcher->dispatch($eventName);

/** @var TraceableProducer $producer */
$producer = static::$container->get('enqueue.producer');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function setUp()
$asyncListener = static::$container->get('enqueue.events.async_listener');

$asyncListener->resetSyncMode();
static::$container->get('test_async_subscriber')->calls = [];
static::$container->get('test_async_listener')->calls = [];
}

public function testCouldBeGetFromContainerAsService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ public function testShouldSendMessageIfDispatchedFromInsideListener()
/** @var EventDispatcherInterface $dispatcher */
$dispatcher = static::$container->get('event_dispatcher');

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

$dispatcher->dispatch('foo');
$dispatcher->dispatch($eventName);

/** @var TraceableProducer $producer */
$producer = static::$container->get('enqueue.producer');
Expand Down
11 changes: 1 addition & 10 deletions pkg/enqueue-bundle/Tests/Functional/QueuesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Enqueue\Client\RouterProcessor;
use Enqueue\Symfony\Client\Meta\QueuesCommand;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\Kernel;

/**
* @group functional
Expand All @@ -30,15 +29,7 @@ public function testShouldDisplayRegisteredQueues()

$this->assertContains(' default ', $display);
$this->assertContains('enqueue.app.default', $display);

$displayId = RouterProcessor::class;
if (30300 > Kernel::VERSION_ID) {
// Symfony 3.2 and below make service identifiers lowercase, so we do the same.
// To be removed when dropping support for Symfony < 3.3.
$displayId = strtolower($displayId);
}

$this->assertContains($displayId, $display);
$this->assertContains(RouterProcessor::class, $display);
}

public function testShouldDisplayRegisteredCommand()
Expand Down
11 changes: 1 addition & 10 deletions pkg/enqueue-bundle/Tests/Functional/TopicsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Enqueue\Client\RouterProcessor;
use Enqueue\Symfony\Client\Meta\TopicsCommand;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\Kernel;

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

$this->assertContains('__router__', $display);

$displayId = RouterProcessor::class;
if (30300 > Kernel::VERSION_ID) {
// Symfony 3.2 and below make service identifiers lowercase, so we do the same.
// To be removed when dropping support for Symfony < 3.3.
$displayId = strtolower($displayId);
}

$this->assertContains($displayId, $display);
$this->assertContains(RouterProcessor::class, $display);
}

public function testShouldDisplayCommands()
Expand Down
13 changes: 5 additions & 8 deletions pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,11 @@ public function provideEnqueueConfigs()
],
]];

// Symfony 2.x does not such env syntax
if (version_compare(Kernel::VERSION, '3.2', '>=')) {
yield 'default_dsn_as_env' => [[
'transport' => [
'default' => '%env(AMQP_DSN)%',
],
]];
}
yield 'default_dsn_as_env' => [[
'transport' => [
'default' => '%env(AMQP_DSN)%',
],
]];

yield 'default_dbal_as_dsn' => [[
'transport' => [
Expand Down
Loading