From e132fd32237bea22496eb8b3d64d15f2e117772a Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Thu, 10 Feb 2022 18:49:44 +0200 Subject: [PATCH 1/6] Add support for Symfony 6 --- .github/workflows/ci.yml | 12 +- .php_cs.php | 12 +- composer.json | 29 ++-- pkg/async-command/composer.json | 16 +- pkg/async-event-dispatcher/composer.json | 12 +- .../Tests/Functional/App/AppKernel.php | 23 ++- .../Tests/Functional/App/CustomAppKernel.php | 23 ++- .../Functional/App/config/config-sf5.yml | 129 ++++++++++++++++ .../Tests/Functional/App/config/config.yml | 5 +- .../App/config/custom-config-sf5.yml | 85 +++++++++++ .../Functional/App/config/custom-config.yml | 2 +- .../Tests/Functional/LazyProducerTest.php | 5 +- .../Tests/Functional/UseCasesTest.php | 7 +- .../Tests/Functional/WebTestCase.php | 5 +- .../DoctrinePingConnectionExtensionTest.php | 2 +- pkg/enqueue-bundle/composer.json | 8 +- pkg/enqueue/Container/Container.php | 2 +- .../DelayRedeliveredMessageExtensionTest.php | 2 +- .../Client/Driver/RabbitMqStompDriverTest.php | 2 +- pkg/enqueue/composer.json | 20 +-- pkg/fs/composer.json | 6 +- .../Tests/Functional/WebTestCase.php | 5 +- .../Tests/Functional/app/AppKernel.php | 23 ++- .../Functional/app/config/config-sf5.yml | 33 ++++ .../Tests/Functional/app/config/config.yml | 2 +- pkg/job-queue/composer.json | 8 +- pkg/simple-client/composer.json | 4 +- pkg/test/TestLogger.php | 144 ++++++++++++++++++ 28 files changed, 505 insertions(+), 121 deletions(-) create mode 100644 pkg/enqueue-bundle/Tests/Functional/App/config/config-sf5.yml create mode 100644 pkg/enqueue-bundle/Tests/Functional/App/config/custom-config-sf5.yml create mode 100644 pkg/job-queue/Tests/Functional/app/config/config-sf5.yml create mode 100644 pkg/test/TestLogger.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eba7de96b..4854df188 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,11 +78,15 @@ jobs: fail-fast: false matrix: php: ['7.3', '7.4', '8.0'] - symfony_version: ['4.4.*', '5.2.*'] + symfony_version: ['4.4.*', '5.2.*', '6.0.*'] dependencies: ['--prefer-lowest', '--prefer-dist'] exclude: - php: '8.0' symfony_version: '4.4.*' + - php: '7.3' + symfony_version: '6.0.*' + - php: '7.4' + symfony_version: '6.0.*' name: PHP ${{ matrix.php }} unit tests on Sf ${{ matrix.symfony_version }}, deps=${{ matrix.dependencies }} @@ -122,12 +126,16 @@ jobs: fail-fast: false matrix: php: ['7.4', '8.0'] # same as in the container - symfony_version: ['4.4.*', '5.2.*'] + symfony_version: ['4.4.*', '5.2.*', '6.0.*'] dependencies: ['--prefer-lowest', '--prefer-dist'] rdkafka_action: ['exclude-group', 'group'] exclude: - php: '8.0' symfony_version: '4.4.*' + - php: '7.3' + symfony_version: '6.0.*' + - php: '7.4' + symfony_version: '6.0.*' name: PHP ${{ matrix.php }} functional tests on Sf ${{ matrix.symfony_version }}, rdkafka_action=${{ matrix.rdkafka_action }}, deps=${{ matrix.dependencies }} diff --git a/.php_cs.php b/.php_cs.php index e28581304..e1755cb13 100644 --- a/.php_cs.php +++ b/.php_cs.php @@ -1,6 +1,6 @@ setRiskyAllowed(true) ->setRules(array( '@Symfony' => true, @@ -8,9 +8,13 @@ 'array_syntax' => array('syntax' => 'short'), 'combine_consecutive_unsets' => true, // one should use PHPUnit methods to set up expected exception instead of annotations - 'general_phpdoc_annotation_remove' => array('expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp'), + 'general_phpdoc_annotation_remove' => ['annotations' => + ['expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp'] + ], 'heredoc_to_nowdoc' => true, - 'no_extra_consecutive_blank_lines' => array('break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'), + 'no_extra_blank_lines' => ['tokens' => [ + 'break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'] + ], 'no_unreachable_default_argument_value' => true, 'no_useless_else' => true, 'no_useless_return' => true, @@ -18,7 +22,7 @@ 'ordered_imports' => true, 'phpdoc_add_missing_param_annotation' => true, 'phpdoc_order' => true, - 'psr4' => true, + 'psr_autoloading' => true, 'strict_param' => true, 'native_function_invocation' => false, )) diff --git a/composer.json b/composer.json index 6f04cc787..fe4e5570f 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "doctrine/dbal": "^2.12|^3.1", "ramsey/uuid": "^3.5|^4", "psr/log": "^1.1 || ^2.0 || ^3.0", - "psr/container": "^1 || ^2.0", + "psr/container": "^1.1 || ^2.0", "makasim/temp-file": "^0.2", "google/cloud-pubsub": "^1.4.3", "doctrine/orm": "^2.7.4", @@ -53,23 +53,23 @@ "phpunit/phpunit": "^9.5", "phpstan/phpstan": "^0.12", "queue-interop/queue-spec": "^0.6.2", - "symfony/browser-kit": "^4.3|^5", - "symfony/config": "^4.3|^5", - "symfony/process": "^4.3|^5", - "symfony/console": "^4.3|^5", - "symfony/dependency-injection": "^4.3|^5", - "symfony/event-dispatcher": "^4.3|^5", - "symfony/expression-language": "^4.3|^5", - "symfony/http-kernel": "^4.3|^5", - "symfony/filesystem": "^4.3|^5", - "symfony/framework-bundle": "^4.3|^5", - "symfony/yaml": "^4.3|^5", + "symfony/browser-kit": "^4.3|^5|^6.0", + "symfony/config": "^4.3|^5|^6.0", + "symfony/process": "^4.3|^5|^6.0", + "symfony/console": "^4.3|^5|^6.0", + "symfony/dependency-injection": "^4.3|^5|^6.0", + "symfony/event-dispatcher": "^4.3|^5|^6.0", + "symfony/expression-language": "^4.3|^5|^6.0", + "symfony/http-kernel": "^4.3|^5|^6.0", + "symfony/filesystem": "^4.3|^5|^6.0", + "symfony/framework-bundle": "^4.3|^5|^6.0", + "symfony/yaml": "^4.3|^5|^6.0", "empi89/php-amqp-stubs": "*@dev", "doctrine/doctrine-bundle": "^2.0", "doctrine/mongodb-odm-bundle": "^3.5|^4.3", "alcaeus/mongo-php-adapter": "^1.0", "kwn/php-rdkafka-stubs": "^2.0.3", - "friendsofphp/php-cs-fixer": "^2", + "friendsofphp/php-cs-fixer": "^3.4", "dms/phpunit-arraysubset-asserts": "^0.2.1", "phpspec/prophecy-phpunit": "^2.0" }, @@ -127,7 +127,8 @@ "ext-mongodb": "1.5", "ext-bcmath": "1", "ext-mbstring": "1", - "ext-mongo": "1.6.14" + "ext-mongo": "1.6.14", + "ext-sockets": "1" }, "prefer-stable": true } diff --git a/pkg/async-command/composer.json b/pkg/async-command/composer.json index 4317d1eca..932499ecf 100644 --- a/pkg/async-command/composer.json +++ b/pkg/async-command/composer.json @@ -9,16 +9,16 @@ "php": "^7.3|^8.0", "enqueue/enqueue": "^0.10", "queue-interop/queue-interop": "^0.8", - "symfony/console": "^4.3|^5", - "symfony/process": "^4.3|^5" + "symfony/console": "^4.3|^5|^6.0", + "symfony/process": "^4.3|^5|^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", - "symfony/dependency-injection": "^4.3|^5", - "symfony/config": "^4.3|^5", - "symfony/http-kernel": "^4.3|^5", - "symfony/filesystem": "^4.3|^5", - "symfony/yaml": "^4.3|^5", + "symfony/dependency-injection": "^4.3|^5|^6.0", + "symfony/config": "^4.3|^5|^6.0", + "symfony/http-kernel": "^4.3|^5|^6.0", + "symfony/filesystem": "^4.3|^5|^6.0", + "symfony/yaml": "^4.3|^5|^6.0", "enqueue/null": "0.10.x-dev", "enqueue/fs": "0.10.x-dev", "enqueue/test": "0.10.x-dev" @@ -31,7 +31,7 @@ "docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md" }, "suggest": { - "symfony/dependency-injection": "^4.3|^5 If you'd like to use async event dispatcher container extension." + "symfony/dependency-injection": "^4.3|^5|^6.0 If you'd like to use async event dispatcher container extension." }, "autoload": { "psr-4": { "Enqueue\\AsyncCommand\\": "" }, diff --git a/pkg/async-event-dispatcher/composer.json b/pkg/async-event-dispatcher/composer.json index d5adc5f7b..28ed42b4f 100644 --- a/pkg/async-event-dispatcher/composer.json +++ b/pkg/async-event-dispatcher/composer.json @@ -9,15 +9,15 @@ "php": "^7.3|^8.0", "enqueue/enqueue": "^0.10", "queue-interop/queue-interop": "^0.8", - "symfony/event-dispatcher": "^4.3|^5" + "symfony/event-dispatcher": "^4.3|^5|^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", - "symfony/dependency-injection": "^4.3|^5", - "symfony/config": "^4.3|^5", - "symfony/http-kernel": "^4.3|^5", - "symfony/filesystem": "^4.3|^5", - "symfony/yaml": "^4.3|^5", + "symfony/dependency-injection": "^4.3|^5|^6.0", + "symfony/config": "^4.3|^5|^6.0", + "symfony/http-kernel": "^4.3|^5|^6.0", + "symfony/filesystem": "^4.3|^5|^6.0", + "symfony/yaml": "^4.3|^5|^6.0", "enqueue/null": "0.10.x-dev", "enqueue/fs": "0.10.x-dev", "enqueue/test": "0.10.x-dev" diff --git a/pkg/enqueue-bundle/Tests/Functional/App/AppKernel.php b/pkg/enqueue-bundle/Tests/Functional/App/AppKernel.php index 49ae1c605..3cafeedda 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/AppKernel.php +++ b/pkg/enqueue-bundle/Tests/Functional/App/AppKernel.php @@ -7,10 +7,7 @@ class AppKernel extends Kernel { - /** - * @return array - */ - public function registerBundles() + public function registerBundles(): iterable { $bundles = [ new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), @@ -21,28 +18,28 @@ public function registerBundles() return $bundles; } - /** - * @return string - */ - public function getCacheDir() + public function getCacheDir(): string { return sys_get_temp_dir().'/EnqueueBundle/cache'; } - /** - * @return string - */ - public function getLogDir() + public function getLogDir(): string { return sys_get_temp_dir().'/EnqueueBundle/cache/logs'; } public function registerContainerConfiguration(LoaderInterface $loader) { + if (self::VERSION_ID < 60000) { + $loader->load(__DIR__.'/config/config-sf5.yml'); + + return; + } + $loader->load(__DIR__.'/config/config.yml'); } - protected function getContainerClass() + protected function getContainerClass(): string { return parent::getContainerClass().'BundleDefault'; } diff --git a/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php b/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php index 2f272bf1b..11fa323d7 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php +++ b/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php @@ -38,10 +38,7 @@ public function setEnqueueConfig(array $config) $fs->mkdir(sys_get_temp_dir().'/EnqueueBundleCustom/cache/'.$this->enqueueConfigId); } - /** - * @return array - */ - public function registerBundles() + public function registerBundles(): iterable { $bundles = [ new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), @@ -52,23 +49,17 @@ public function registerBundles() return $bundles; } - /** - * @return string - */ - public function getCacheDir() + public function getCacheDir(): string { return sys_get_temp_dir().'/EnqueueBundleCustom/cache/'.$this->enqueueConfigId; } - /** - * @return string - */ - public function getLogDir() + public function getLogDir(): string { return sys_get_temp_dir().'/EnqueueBundleCustom/cache/logs/'.$this->enqueueConfigId; } - protected function getContainerClass() + protected function getContainerClass(): string { return parent::getContainerClass().'Custom'.$this->enqueueConfigId; } @@ -78,7 +69,11 @@ protected function getContainerClass() */ protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) { - $loader->load(__DIR__.'/config/custom-config.yml'); + if (self::VERSION_ID < 60000) { + $loader->load(__DIR__.'/config/custom-config-sf5.yml'); + } else { + $loader->load(__DIR__.'/config/custom-config.yml'); + } $c->loadFromExtension('enqueue', $this->enqueueConfig); } diff --git a/pkg/enqueue-bundle/Tests/Functional/App/config/config-sf5.yml b/pkg/enqueue-bundle/Tests/Functional/App/config/config-sf5.yml new file mode 100644 index 000000000..441dcb120 --- /dev/null +++ b/pkg/enqueue-bundle/Tests/Functional/App/config/config-sf5.yml @@ -0,0 +1,129 @@ +parameters: + locale: 'en' + secret: 'ThisTokenIsNotSoSecretChangeIt' + + +framework: + #esi: ~ + #translator: { fallback: "%locale%" } + test: ~ + assets: false + session: + # the only option incompatible with Symfony 6 + storage_id: session.storage.mock_file + secret: '%secret%' + router: { resource: '%kernel.project_dir%/config/routing.yml' } + default_locale: '%locale%' + +doctrine: + dbal: + url: "%env(DOCTRINE_DSN)%" + driver: pdo_mysql + charset: UTF8 + +enqueue: + default: + transport: 'null:' + client: + traceable_producer: true + job: true + async_events: true + async_commands: + enabled: true + timeout: 60 + command_name: ~ + queue_name: ~ + +services: + test_enqueue.client.default.traceable_producer: + alias: 'enqueue.client.default.traceable_producer' + public: true + + test_enqueue.transport.default.queue_consumer: + alias: 'enqueue.transport.default.queue_consumer' + public: true + + test_enqueue.client.default.queue_consumer: + alias: 'enqueue.client.default.queue_consumer' + public: true + + test_enqueue.transport.default.rpc_client: + alias: 'enqueue.transport.default.rpc_client' + public: true + + test_enqueue.client.default.producer: + alias: 'enqueue.client.default.producer' + public: true + + test_enqueue.client.default.spool_producer: + alias: 'enqueue.client.default.spool_producer' + public: true + + test_Enqueue\Client\ProducerInterface: + alias: 'Enqueue\Client\ProducerInterface' + public: true + + test_enqueue.client.default.driver: + alias: 'enqueue.client.default.driver' + public: true + + test_enqueue.transport.default.context: + alias: 'enqueue.transport.default.context' + public: true + + test_enqueue.client.consume_command: + alias: 'enqueue.client.consume_command' + public: true + + test.enqueue.client.routes_command: + alias: 'enqueue.client.routes_command' + public: true + + test.enqueue.events.async_processor: + alias: 'enqueue.events.async_processor' + public: true + + test_async_listener: + class: 'Enqueue\Bundle\Tests\Functional\App\TestAsyncListener' + public: true + tags: + - { name: 'kernel.event_listener', async: true, event: 'test_async', method: 'onEvent' } + + test_command_subscriber_processor: + class: 'Enqueue\Bundle\Tests\Functional\App\TestCommandSubscriberProcessor' + public: true + tags: + - { name: 'enqueue.command_subscriber', client: 'default' } + + test_topic_subscriber_processor: + class: 'Enqueue\Bundle\Tests\Functional\App\TestTopicSubscriberProcessor' + public: true + tags: + - { name: 'enqueue.topic_subscriber', client: 'default' } + + test_exclusive_command_subscriber_processor: + class: 'Enqueue\Bundle\Tests\Functional\App\TestExclusiveCommandSubscriberProcessor' + public: true + tags: + - { name: 'enqueue.command_subscriber', client: 'default' } + + test_async_subscriber: + class: 'Enqueue\Bundle\Tests\Functional\App\TestAsyncSubscriber' + public: true + tags: + - { name: 'kernel.event_subscriber', async: true } + + test_async_event_transformer: + class: 'Enqueue\Bundle\Tests\Functional\App\TestAsyncEventTransformer' + public: true + arguments: + - '@enqueue.transport.default.context' + tags: + - {name: 'enqueue.event_transformer', eventName: 'test_async', transformerName: 'test_async' } + - {name: 'enqueue.event_transformer', eventName: 'test_async_subscriber', transformerName: 'test_async' } + + # overwrite async listener with one based on client producer. so we can use traceable producer. + enqueue.events.async_listener: + class: 'Enqueue\Bundle\Tests\Functional\App\AsyncListener' + public: true + arguments: ['@enqueue.client.default.producer', '@enqueue.events.registry'] diff --git a/pkg/enqueue-bundle/Tests/Functional/App/config/config.yml b/pkg/enqueue-bundle/Tests/Functional/App/config/config.yml index 7b04a3f30..f2a7d336a 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/config/config.yml +++ b/pkg/enqueue-bundle/Tests/Functional/App/config/config.yml @@ -9,7 +9,7 @@ framework: test: ~ assets: false session: - storage_id: session.storage.mock_file + storage_factory_id: session.storage.factory.mock_file secret: '%secret%' router: { resource: '%kernel.project_dir%/config/routing.yml' } default_locale: '%locale%' @@ -126,3 +126,6 @@ services: class: 'Enqueue\Bundle\Tests\Functional\App\AsyncListener' public: true arguments: ['@enqueue.client.default.producer', '@enqueue.events.registry'] + + locale_aware_listener: + public: true diff --git a/pkg/enqueue-bundle/Tests/Functional/App/config/custom-config-sf5.yml b/pkg/enqueue-bundle/Tests/Functional/App/config/custom-config-sf5.yml new file mode 100644 index 000000000..35192652e --- /dev/null +++ b/pkg/enqueue-bundle/Tests/Functional/App/config/custom-config-sf5.yml @@ -0,0 +1,85 @@ +parameters: + locale: 'en' + secret: 'ThisTokenIsNotSoSecretChangeIt' + +framework: + #esi: ~ + #translator: { fallback: "%locale%" } + test: ~ + assets: false + session: + # the only option incompatible with Symfony 6 + storage_id: session.storage.mock_file + secret: '%secret%' + router: { resource: '%kernel.project_dir%/config/routing.yml' } + default_locale: '%locale%' + +doctrine: + dbal: + connections: + custom: + url: "%env(DOCTRINE_DSN)%" + driver: pdo_mysql + charset: UTF8 + +services: + test_enqueue.client.default.driver: + alias: 'enqueue.client.default.driver' + public: true + + test_enqueue.client.default.producer: + alias: 'enqueue.client.default.producer' + public: true + + test_enqueue.client.default.lazy_producer: + alias: 'enqueue.client.default.lazy_producer' + public: true + + test_enqueue.transport.default.context: + alias: 'enqueue.transport.default.context' + public: true + + test_enqueue.transport.consume_command: + alias: 'enqueue.transport.consume_command' + public: true + + test_enqueue.client.consume_command: + alias: 'enqueue.client.consume_command' + public: true + + test_enqueue.client.produce_command: + alias: 'enqueue.client.produce_command' + public: true + + test_enqueue.client.setup_broker_command: + alias: 'enqueue.client.setup_broker_command' + public: true + + test.message.processor: + class: 'Enqueue\Bundle\Tests\Functional\TestProcessor' + public: true + tags: + - { name: 'enqueue.topic_subscriber', client: 'default' } + - { name: 'enqueue.transport.processor', transport: 'default' } + + test.message.command_processor: + class: 'Enqueue\Bundle\Tests\Functional\TestCommandProcessor' + public: true + tags: + - { name: 'enqueue.command_subscriber', client: 'default' } + + test.sqs_client: + public: true + class: 'Aws\Sqs\SqsClient' + arguments: + - + endpoint: '%env(AWS_SQS_ENDPOINT)%' + region: '%env(AWS_SQS_REGION)%' + version: '%env(AWS_SQS_VERSION)%' + credentials: + key: '%env(AWS_SQS_KEY)%' + secret: '%env(AWS_SQS_SECRET)%' + + test.sqs_custom_connection_factory_factory: + class: 'Enqueue\Bundle\Tests\Functional\App\SqsCustomConnectionFactoryFactory' + arguments: ['@service_container'] diff --git a/pkg/enqueue-bundle/Tests/Functional/App/config/custom-config.yml b/pkg/enqueue-bundle/Tests/Functional/App/config/custom-config.yml index 37c4660a0..d02f3002d 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/config/custom-config.yml +++ b/pkg/enqueue-bundle/Tests/Functional/App/config/custom-config.yml @@ -8,7 +8,7 @@ framework: test: ~ assets: false session: - storage_id: session.storage.mock_file + storage_factory_id: session.storage.factory.mock_file secret: '%secret%' router: { resource: '%kernel.project_dir%/config/routing.yml' } default_locale: '%locale%' diff --git a/pkg/enqueue-bundle/Tests/Functional/LazyProducerTest.php b/pkg/enqueue-bundle/Tests/Functional/LazyProducerTest.php index 19f139b69..858b80a1c 100644 --- a/pkg/enqueue-bundle/Tests/Functional/LazyProducerTest.php +++ b/pkg/enqueue-bundle/Tests/Functional/LazyProducerTest.php @@ -47,10 +47,7 @@ public function testShouldAllowGetLazyProducerWithoutError() $producer->sendEvent('foo', 'foo'); } - /** - * @return string - */ - public static function getKernelClass() + public static function getKernelClass(): string { include_once __DIR__.'/App/CustomAppKernel.php'; diff --git a/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php b/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php index af4159c25..ad278d599 100644 --- a/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php +++ b/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php @@ -18,7 +18,7 @@ */ class UseCasesTest extends WebTestCase { - const RECEIVE_TIMEOUT = 500; + private const RECEIVE_TIMEOUT = 500; protected function setUp(): void { @@ -360,10 +360,7 @@ public function testTransportConsumeCommandShouldConsumeOneMessage() $this->assertEquals($expectedBody, $processor->message->getBody()); } - /** - * @return string - */ - public static function getKernelClass() + public static function getKernelClass(): string { include_once __DIR__.'/App/CustomAppKernel.php'; diff --git a/pkg/enqueue-bundle/Tests/Functional/WebTestCase.php b/pkg/enqueue-bundle/Tests/Functional/WebTestCase.php index ca462ea1e..6a348a9f3 100644 --- a/pkg/enqueue-bundle/Tests/Functional/WebTestCase.php +++ b/pkg/enqueue-bundle/Tests/Functional/WebTestCase.php @@ -39,10 +39,7 @@ protected function tearDown(): void static::$client = null; } - /** - * @return string - */ - public static function getKernelClass() + public static function getKernelClass(): string { include_once __DIR__.'/App/AppKernel.php'; diff --git a/pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrinePingConnectionExtensionTest.php b/pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrinePingConnectionExtensionTest.php index 341ca5c23..c530eeaa9 100644 --- a/pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrinePingConnectionExtensionTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrinePingConnectionExtensionTest.php @@ -7,13 +7,13 @@ use Doctrine\Persistence\ManagerRegistry; use Enqueue\Bundle\Consumption\Extension\DoctrinePingConnectionExtension; use Enqueue\Consumption\Context\MessageReceived; +use Enqueue\Test\TestLogger; use Interop\Queue\Consumer; use Interop\Queue\Context as InteropContext; use Interop\Queue\Message; use Interop\Queue\Processor; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Psr\Log\Test\TestLogger; class DoctrinePingConnectionExtensionTest extends TestCase { diff --git a/pkg/enqueue-bundle/composer.json b/pkg/enqueue-bundle/composer.json index b7be27e25..835380458 100644 --- a/pkg/enqueue-bundle/composer.json +++ b/pkg/enqueue-bundle/composer.json @@ -7,7 +7,7 @@ "license": "MIT", "require": { "php": "^7.3|^8.0", - "symfony/framework-bundle": "^4.3|^5", + "symfony/framework-bundle": "^4.3|^5|^6.0", "queue-interop/amqp-interop": "^0.8.2", "queue-interop/queue-interop": "^0.8", "enqueue/enqueue": "^0.10", @@ -45,9 +45,9 @@ "doctrine/doctrine-bundle": "^2.0", "doctrine/mongodb-odm-bundle": "^3.5|^4.3", "alcaeus/mongo-php-adapter": "^1.0", - "symfony/browser-kit": "^4.3|^5", - "symfony/expression-language": "^4.3|^5", - "symfony/yaml": "^4.3|^5" + "symfony/browser-kit": "^4.3|^5|^6.0", + "symfony/expression-language": "^4.3|^5|^6.0", + "symfony/yaml": "^4.3|^5|^6.0" }, "suggest": { "enqueue/async-command": "If want to run Symfony command via message queue", diff --git a/pkg/enqueue/Container/Container.php b/pkg/enqueue/Container/Container.php index 255def33b..5abec276c 100644 --- a/pkg/enqueue/Container/Container.php +++ b/pkg/enqueue/Container/Container.php @@ -25,7 +25,7 @@ public function get($id) return $this->services[$id]; } - public function has($id) + public function has(string $id): bool { return array_key_exists($id, $this->services); } diff --git a/pkg/enqueue/Tests/Client/ConsumptionExtension/DelayRedeliveredMessageExtensionTest.php b/pkg/enqueue/Tests/Client/ConsumptionExtension/DelayRedeliveredMessageExtensionTest.php index a92dc8df1..0481d27d8 100644 --- a/pkg/enqueue/Tests/Client/ConsumptionExtension/DelayRedeliveredMessageExtensionTest.php +++ b/pkg/enqueue/Tests/Client/ConsumptionExtension/DelayRedeliveredMessageExtensionTest.php @@ -10,6 +10,7 @@ use Enqueue\Consumption\Result; use Enqueue\Null\NullMessage; use Enqueue\Null\NullQueue; +use Enqueue\Test\TestLogger; use Interop\Queue\Consumer; use Interop\Queue\Context as InteropContext; use Interop\Queue\Destination; @@ -19,7 +20,6 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Log\NullLogger; -use Psr\Log\Test\TestLogger; class DelayRedeliveredMessageExtensionTest extends TestCase { diff --git a/pkg/enqueue/Tests/Client/Driver/RabbitMqStompDriverTest.php b/pkg/enqueue/Tests/Client/Driver/RabbitMqStompDriverTest.php index fbcb68644..9fc72be1e 100644 --- a/pkg/enqueue/Tests/Client/Driver/RabbitMqStompDriverTest.php +++ b/pkg/enqueue/Tests/Client/Driver/RabbitMqStompDriverTest.php @@ -18,13 +18,13 @@ use Enqueue\Stomp\StompMessage; use Enqueue\Stomp\StompProducer; use Enqueue\Test\ClassExtensionTrait; +use Enqueue\Test\TestLogger; use Interop\Queue\Context; use Interop\Queue\Message as InteropMessage; use Interop\Queue\Producer as InteropProducer; use Interop\Queue\Queue as InteropQueue; use Interop\Queue\Topic as InteropTopic; use PHPUnit\Framework\TestCase; -use Psr\Log\Test\TestLogger; class RabbitMqStompDriverTest extends TestCase { diff --git a/pkg/enqueue/composer.json b/pkg/enqueue/composer.json index fdb365761..82c77527e 100644 --- a/pkg/enqueue/composer.json +++ b/pkg/enqueue/composer.json @@ -13,16 +13,16 @@ "enqueue/dsn": "^0.10", "ramsey/uuid": "^3.5|^4", "psr/log": "^1.0 || ^2.0 || ^3.0", - "psr/container": "^1 || ^2.0" + "psr/container": "^1.1 || ^2.0" }, "require-dev": { "phpunit/phpunit": "^9.5", - "symfony/console": "^4.3|^5", - "symfony/dependency-injection": "^4.3|^5", - "symfony/config": "^4.3|^5", - "symfony/event-dispatcher": "^4.3|^5", - "symfony/http-kernel": "^4.3|^5", - "symfony/yaml": "^4.3|^5", + "symfony/console": "^4.3|^5|^6.0", + "symfony/dependency-injection": "^4.3|^5|^6.0", + "symfony/config": "^4.3|^5|^6.0", + "symfony/event-dispatcher": "^4.3|^5|^6.0", + "symfony/http-kernel": "^4.3|^5|^6.0", + "symfony/yaml": "^4.3|^5|^6.0", "enqueue/amqp-ext": "0.10.x-dev", "enqueue/amqp-lib": "0.10.x-dev", "enqueue/amqp-bunny": "0.10.x-dev", @@ -42,9 +42,9 @@ "enqueue/dsn": "0.10.x-dev" }, "suggest": { - "symfony/console": "^2.8|^3|^4|^5 If you want to use cli commands", - "symfony/dependency-injection": "^4.3|^5", - "symfony/config": "^4.3|^5", + "symfony/console": "^2.8|^3|^4|^5|^6.0 If you want to use cli commands", + "symfony/dependency-injection": "^4.3|^5|^6.0", + "symfony/config": "^4.3|^5|^6.0", "enqueue/amqp-ext": "AMQP transport (based on php extension)", "enqueue/stomp": "STOMP transport", "enqueue/fs": "Filesystem transport", diff --git a/pkg/fs/composer.json b/pkg/fs/composer.json index 54f91e378..193d603d3 100644 --- a/pkg/fs/composer.json +++ b/pkg/fs/composer.json @@ -9,7 +9,7 @@ "php": "^7.3|^8.0", "queue-interop/queue-interop": "^0.8", "enqueue/dsn": "^0.10", - "symfony/filesystem": "^4.3|^5", + "symfony/filesystem": "^4.3|^5|^6.0", "makasim/temp-file": "^0.2@stable" }, "require-dev": { @@ -17,8 +17,8 @@ "enqueue/null": "0.10.x-dev", "enqueue/test": "0.10.x-dev", "queue-interop/queue-spec": "^0.6.2", - "symfony/dependency-injection": "^4.3|^5", - "symfony/yaml": "^4.3|^5" + "symfony/dependency-injection": "^4.3|^5|^6.0", + "symfony/yaml": "^4.3|^5|^6.0" }, "support": { "email": "opensource@forma-pro.com", diff --git a/pkg/job-queue/Tests/Functional/WebTestCase.php b/pkg/job-queue/Tests/Functional/WebTestCase.php index 90a8188dd..cd990384a 100644 --- a/pkg/job-queue/Tests/Functional/WebTestCase.php +++ b/pkg/job-queue/Tests/Functional/WebTestCase.php @@ -40,10 +40,7 @@ protected function tearDown(): void static::ensureKernelShutdown(); } - /** - * @return string - */ - public static function getKernelClass() + public static function getKernelClass(): string { require_once __DIR__.'/app/AppKernel.php'; diff --git a/pkg/job-queue/Tests/Functional/app/AppKernel.php b/pkg/job-queue/Tests/Functional/app/AppKernel.php index 9e6a24812..3cef602c2 100644 --- a/pkg/job-queue/Tests/Functional/app/AppKernel.php +++ b/pkg/job-queue/Tests/Functional/app/AppKernel.php @@ -7,10 +7,7 @@ class AppKernel extends Kernel { - /** - * @return array - */ - public function registerBundles() + public function registerBundles(): iterable { $bundles = [ new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), @@ -20,28 +17,28 @@ public function registerBundles() return $bundles; } - /** - * @return string - */ - public function getCacheDir() + public function getCacheDir(): string { return sys_get_temp_dir().'/EnqueueJobQueue/cache'; } - /** - * @return string - */ - public function getLogDir() + public function getLogDir(): string { return sys_get_temp_dir().'/EnqueueJobQueue/cache/logs'; } public function registerContainerConfiguration(LoaderInterface $loader) { + if (self::VERSION_ID < 60000) { + $loader->load(__DIR__.'/config/config-sf5.yml'); + + return; + } + $loader->load(__DIR__.'/config/config.yml'); } - protected function getContainerClass() + protected function getContainerClass(): string { return parent::getContainerClass().'JobQueue'; } diff --git a/pkg/job-queue/Tests/Functional/app/config/config-sf5.yml b/pkg/job-queue/Tests/Functional/app/config/config-sf5.yml new file mode 100644 index 000000000..dd3467e11 --- /dev/null +++ b/pkg/job-queue/Tests/Functional/app/config/config-sf5.yml @@ -0,0 +1,33 @@ +parameters: + locale: 'en' + secret: 'ThisTokenIsNotSoSecretChangeIt' + +framework: + #esi: ~ + #translator: { fallback: "%locale%" } + test: ~ + assets: false + session: + # the only option incompatible with Symfony 6 + storage_id: session.storage.mock_file + secret: "%secret%" + router: { resource: "%kernel.project_dir%/config/routing.yml" } + default_locale: "%locale%" + +doctrine: + dbal: + url: "%env(DOCTRINE_DSN)%" + driver: pdo_mysql + charset: UTF8 + wrapper_class: "Enqueue\\JobQueue\\Test\\DbalPersistedConnection" + orm: + auto_generate_proxy_classes: true + auto_mapping: true + mappings: + TestEntity: + mapping: true + type: annotation + dir: '%kernel.project_dir%/Tests/Functional/Entity' + alias: 'EnqueueJobQueue' + prefix: 'Enqueue\JobQueue\Tests\Functional\Entity' + is_bundle: false diff --git a/pkg/job-queue/Tests/Functional/app/config/config.yml b/pkg/job-queue/Tests/Functional/app/config/config.yml index b6d642b82..47cded132 100644 --- a/pkg/job-queue/Tests/Functional/app/config/config.yml +++ b/pkg/job-queue/Tests/Functional/app/config/config.yml @@ -8,7 +8,7 @@ framework: test: ~ assets: false session: - storage_id: session.storage.mock_file + storage_factory_id: session.storage.factory.mock_file secret: "%secret%" router: { resource: "%kernel.project_dir%/config/routing.yml" } default_locale: "%locale%" diff --git a/pkg/job-queue/composer.json b/pkg/job-queue/composer.json index 2a41c1b92..998245e4b 100644 --- a/pkg/job-queue/composer.json +++ b/pkg/job-queue/composer.json @@ -17,10 +17,10 @@ "phpunit/phpunit": "^9.5", "enqueue/test": "0.10.x-dev", "doctrine/doctrine-bundle": "^2.0", - "symfony/browser-kit": "^4.3|^5", - "symfony/expression-language": "^4.3|^5", - "symfony/framework-bundle": "^4.3|^5", - "symfony/yaml": "^4.3|^5" + "symfony/browser-kit": "^4.3|^5|^6.0", + "symfony/expression-language": "^4.3|^5|^6.0", + "symfony/framework-bundle": "^4.3|^5|^6.0", + "symfony/yaml": "^4.3|^5|^6.0" }, "support": { "email": "opensource@forma-pro.com", diff --git a/pkg/simple-client/composer.json b/pkg/simple-client/composer.json index 02e8a93f7..037bf3fcd 100644 --- a/pkg/simple-client/composer.json +++ b/pkg/simple-client/composer.json @@ -10,7 +10,7 @@ "enqueue/enqueue": "^0.10", "queue-interop/amqp-interop": "^0.8.2", "queue-interop/queue-interop": "^0.8", - "symfony/config": "^4.3|^5" + "symfony/config": "^4.3|^5|^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", @@ -18,7 +18,7 @@ "enqueue/amqp-ext": "0.10.x-dev", "enqueue/fs": "0.10.x-dev", "enqueue/null": "0.10.x-dev", - "symfony/yaml": "^4.3|^5" + "symfony/yaml": "^4.3|^5|^6.0" }, "support": { "email": "opensource@forma-pro.com", diff --git a/pkg/test/TestLogger.php b/pkg/test/TestLogger.php new file mode 100644 index 000000000..d61c67932 --- /dev/null +++ b/pkg/test/TestLogger.php @@ -0,0 +1,144 @@ + 0) { + $genericMethod = $matches[1].('Records' !== $matches[3] ? 'Record' : '').$matches[3]; + $level = strtolower($matches[2]); + if (method_exists($this, $genericMethod)) { + $args[] = $level; + + return call_user_func_array([$this, $genericMethod], $args); + } + } + throw new \BadMethodCallException('Call to undefined method TestLogger::'.$method.'()'); + } + + public function log($level, $message, array $context = []): void + { + $record = [ + 'level' => $level, + 'message' => $message, + 'context' => $context, + ]; + + $this->recordsByLevel[$record['level']][] = $record; + $this->records[] = $record; + } + + public function hasRecords($level) + { + return isset($this->recordsByLevel[$level]); + } + + public function hasRecord($record, $level) + { + if (is_string($record)) { + $record = ['message' => $record]; + } + + return $this->hasRecordThatPasses(function ($rec) use ($record) { + if ($rec['message'] !== $record['message']) { + return false; + } + if (isset($record['context']) && $rec['context'] !== $record['context']) { + return false; + } + + return true; + }, $level); + } + + public function hasRecordThatContains($message, $level) + { + return $this->hasRecordThatPasses(function ($rec) use ($message) { + return false !== strpos($rec['message'], $message); + }, $level); + } + + public function hasRecordThatMatches($regex, $level) + { + return $this->hasRecordThatPasses(function ($rec) use ($regex) { + return preg_match($regex, $rec['message']) > 0; + }, $level); + } + + public function hasRecordThatPasses(callable $predicate, $level) + { + if (!isset($this->recordsByLevel[$level])) { + return false; + } + foreach ($this->recordsByLevel[$level] as $i => $rec) { + if (call_user_func($predicate, $rec, $i)) { + return true; + } + } + + return false; + } + + public function reset() + { + $this->records = []; + $this->recordsByLevel = []; + } +} From 0ea448c3c3ca1fefdb3715e939c33012b815a391 Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Tue, 15 Feb 2022 21:25:41 +0200 Subject: [PATCH 2/6] Clean up and typos --- pkg/async-event-dispatcher/README.md | 8 ++++---- pkg/enqueue-bundle/composer.json | 6 ------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/pkg/async-event-dispatcher/README.md b/pkg/async-event-dispatcher/README.md index 1ba408fa7..f1629b59a 100644 --- a/pkg/async-event-dispatcher/README.md +++ b/pkg/async-event-dispatcher/README.md @@ -10,12 +10,12 @@ Enqueue is an MIT-licensed open source project with its ongoing development made # Symfony Async Event Dispatcher. [![Gitter](https://badges.gitter.im/php-enqueue/Lobby.svg)](https://gitter.im/php-enqueue/Lobby) -[![Build Status](https://img.shields.io/github/workflow/status/php-enqueue/async-event-dispathcer/CI)](https://github.com/php-enqueue/async-event-dispathcer/actions?query=workflow%3ACI) -[![Total Downloads](https://poser.pugx.org/enqueue/async-event-dispathcer/d/total.png)](https://packagist.org/packages/enqueue/async-event-dispathcer) -[![Latest Stable Version](https://poser.pugx.org/enqueue/async-event-dispathcer/version.png)](https://packagist.org/packages/enqueue/async-event-dispathcer) +[![Build Status](https://img.shields.io/github/workflow/status/php-enqueue/async-event-dispatcher/CI)](https://github.com/php-enqueue/async-event-dispathcer/actions?query=workflow%3ACI) +[![Total Downloads](https://poser.pugx.org/enqueue/async-event-dispathcer/d/total.png)](https://packagist.org/packages/enqueue/async-event-dispatcher) +[![Latest Stable Version](https://poser.pugx.org/enqueue/async-event-dispathcer/version.png)](https://packagist.org/packages/enqueue/async-event-dispatcher) It contains an extension to Symfony's [EventDispatcher](https://symfony.com/doc/current/components/event_dispatcher.html) component. -It allows to processes events in background by sending them to MQ. +It allows to process events in background by sending them to MQ. ## Resources diff --git a/pkg/enqueue-bundle/composer.json b/pkg/enqueue-bundle/composer.json index 835380458..70eda07bd 100644 --- a/pkg/enqueue-bundle/composer.json +++ b/pkg/enqueue-bundle/composer.json @@ -20,12 +20,6 @@ "source": "https://github.com/php-enqueue/enqueue-dev", "docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md" }, - "repositories": [ - { - "type": "git", - "url": "https://github.com/andrewmy/php-rabbitmq-management-api.git" - } - ], "require-dev": { "phpunit/phpunit": "^9.5", "enqueue/stomp": "0.10.x-dev", From e10a894a146792a362e50c48f17bfe15153f2124 Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Tue, 15 Feb 2022 21:47:24 +0200 Subject: [PATCH 3/6] Fix events compatibility --- .../DependencyInjection/AsyncEventsPass.php | 51 +++++++++++++++---- .../Functional/App/config/config-sf5.yml | 4 +- .../Tests/Functional/App/config/config.yml | 4 +- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php b/pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php index 5371eb869..e57d710f7 100644 --- a/pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php +++ b/pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php @@ -6,6 +6,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\Kernel; class AsyncEventsPass implements CompilerPassInterface { @@ -21,6 +22,9 @@ public function process(ContainerBuilder $container): void $defaultClient = $container->getParameter('enqueue.default_client'); + // TODO: Remove when dropping Symfony < 5.3 + $useLegacyDispatcherConfig = (Kernel::VERSION_ID < 50300); + $registeredToEvent = []; foreach ($container->findTaggedServiceIds('kernel.event_listener') as $serviceId => $tagAttributes) { foreach ($tagAttributes as $tagAttribute) { @@ -32,8 +36,10 @@ public function process(ContainerBuilder $container): void $service = $container->getDefinition($serviceId); - $service->clearTag('kernel.event_listener'); - $service->addTag('enqueue.async_event_listener', $tagAttribute); + if ($useLegacyDispatcherConfig) { + $service->clearTag('kernel.event_listener'); + $service->addTag('enqueue.async_event_listener', $tagAttribute); + } if (false == isset($registeredToEvent[$event])) { $container->getDefinition('enqueue.events.async_listener') @@ -43,6 +49,16 @@ public function process(ContainerBuilder $container): void ]) ; + if (!$useLegacyDispatcherConfig) { + $container->getDefinition('enqueue.events.async_listener') + ->addTag('kernel.event_listener', [ + 'event' => $event, + 'method' => 'onEvent', + 'dispatcher' => 'enqueue.events.event_dispatcher', + ]) + ; + } + $container->getDefinition('enqueue.events.async_processor') ->addTag('enqueue.processor', [ 'topic' => 'event.'.$event, @@ -62,8 +78,11 @@ public function process(ContainerBuilder $container): void } $service = $container->getDefinition($serviceId); - $service->clearTag('kernel.event_subscriber'); - $service->addTag('enqueue.async_event_subscriber', $tagAttribute); + + if ($useLegacyDispatcherConfig) { + $service->clearTag('kernel.event_subscriber'); + $service->addTag('enqueue.async_event_subscriber', $tagAttribute); + } /** @var EventSubscriberInterface $serviceClass */ $serviceClass = $service->getClass(); @@ -77,6 +96,16 @@ public function process(ContainerBuilder $container): void ]) ; + if (!$useLegacyDispatcherConfig) { + $container->getDefinition('enqueue.events.async_listener') + ->addTag('kernel.event_listener', [ + 'event' => $event, + 'method' => 'onEvent', + 'dispatcher' => 'enqueue.events.event_dispatcher', + ]) + ; + } + $container->getDefinition('enqueue.events.async_processor') ->addTag('enqueue.processor', [ 'topicName' => 'event.'.$event, @@ -90,11 +119,13 @@ public function process(ContainerBuilder $container): void } } - $registerListenersPass = new RegisterListenersPass( - 'enqueue.events.event_dispatcher', - 'enqueue.async_event_listener', - 'enqueue.async_event_subscriber' - ); - $registerListenersPass->process($container); + if ($useLegacyDispatcherConfig) { + $registerListenersPass = new RegisterListenersPass( + 'enqueue.events.event_dispatcher', + 'enqueue.async_event_listener', + 'enqueue.async_event_subscriber' + ); + $registerListenersPass->process($container); + } } } diff --git a/pkg/enqueue-bundle/Tests/Functional/App/config/config-sf5.yml b/pkg/enqueue-bundle/Tests/Functional/App/config/config-sf5.yml index 441dcb120..3a4f7795d 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/config/config-sf5.yml +++ b/pkg/enqueue-bundle/Tests/Functional/App/config/config-sf5.yml @@ -9,7 +9,7 @@ framework: test: ~ assets: false session: - # the only option incompatible with Symfony 6 + # option incompatible with Symfony 6 storage_id: session.storage.mock_file secret: '%secret%' router: { resource: '%kernel.project_dir%/config/routing.yml' } @@ -88,6 +88,7 @@ services: public: true tags: - { name: 'kernel.event_listener', async: true, event: 'test_async', method: 'onEvent' } + # In Symfony 6 you would also add "dispatcher: 'enqueue.events.event_dispatcher'" test_command_subscriber_processor: class: 'Enqueue\Bundle\Tests\Functional\App\TestCommandSubscriberProcessor' @@ -112,6 +113,7 @@ services: public: true tags: - { name: 'kernel.event_subscriber', async: true } + # In Symfony 6 you would also add "dispatcher: 'enqueue.events.event_dispatcher'" test_async_event_transformer: class: 'Enqueue\Bundle\Tests\Functional\App\TestAsyncEventTransformer' diff --git a/pkg/enqueue-bundle/Tests/Functional/App/config/config.yml b/pkg/enqueue-bundle/Tests/Functional/App/config/config.yml index f2a7d336a..0a33b27a7 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/config/config.yml +++ b/pkg/enqueue-bundle/Tests/Functional/App/config/config.yml @@ -86,7 +86,7 @@ services: class: 'Enqueue\Bundle\Tests\Functional\App\TestAsyncListener' public: true tags: - - { name: 'kernel.event_listener', async: true, event: 'test_async', method: 'onEvent' } + - { name: 'kernel.event_listener', async: true, event: 'test_async', method: 'onEvent', dispatcher: 'enqueue.events.event_dispatcher' } test_command_subscriber_processor: class: 'Enqueue\Bundle\Tests\Functional\App\TestCommandSubscriberProcessor' @@ -110,7 +110,7 @@ services: class: 'Enqueue\Bundle\Tests\Functional\App\TestAsyncSubscriber' public: true tags: - - { name: 'kernel.event_subscriber', async: true } + - { name: 'kernel.event_subscriber', async: true, dispatcher: 'enqueue.events.event_dispatcher' } test_async_event_transformer: class: 'Enqueue\Bundle\Tests\Functional\App\TestAsyncEventTransformer' From 8f0bcd6541df947e4b09fbc9f7c2621d9a8d2593 Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Wed, 16 Feb 2022 10:14:37 +0200 Subject: [PATCH 4/6] Update docs --- docs/bundle/async_events.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/bundle/async_events.md b/docs/bundle/async_events.md index 7264f5f20..99b674a76 100644 --- a/docs/bundle/async_events.md +++ b/docs/bundle/async_events.md @@ -39,7 +39,7 @@ enqueue: ## Usage -To make your listener async you have add `async: true` attribute to the tag `kernel.event_listener`, like this: +To make your listener async you have add `async: true` (every version) and `dispatcher: 'enqueue.events.event_dispatcher'` (since Symfony 5.3) attributes to the tag `kernel.event_listener`, like this: ```yaml # app/config/config.yml @@ -48,7 +48,7 @@ services: acme.foo_listener: class: 'AcmeBundle\Listener\FooListener' tags: - - { name: 'kernel.event_listener', async: true, event: 'foo', method: 'onEvent' } + - { name: 'kernel.event_listener', async: true, event: 'foo', method: 'onEvent', dispatcher: 'enqueue.events.event_dispatcher' } ``` or to `kernel.event_subscriber`: @@ -60,7 +60,7 @@ services: test_async_subscriber: class: 'AcmeBundle\Listener\TestAsyncSubscriber' tags: - - { name: 'kernel.event_subscriber', async: true } + - { name: 'kernel.event_subscriber', async: true, dispatcher: 'enqueue.events.event_dispatcher' } ``` That's basically it. The rest of the doc describes advanced features. @@ -78,7 +78,7 @@ services: public: false arguments: ['@enqueue.transport.default.context', '@enqueue.events.registry', 'a_queue_name'] tags: - - { name: 'kernel.event_listener', event: 'foo', method: 'onEvent' } + - { name: 'kernel.event_listener', event: 'foo', method: 'onEvent', dispatcher: 'enqueue.events.event_dispatcher' } ``` From e82d4ae973435fd83cbeb3f969137ae456bb2c65 Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Wed, 16 Feb 2022 13:14:49 +0200 Subject: [PATCH 5/6] =?UTF-8?q?Drop=20Symfony=20<=205.1=20=F0=9F=94=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 8 +- composer.json | 22 ++-- docs/bundle/async_events.md | 2 +- pkg/async-command/composer.json | 16 +-- .../AsyncEventDispatcher.php | 47 ++------ pkg/async-event-dispatcher/AsyncListener.php | 66 +++--------- .../DependencyInjection/AsyncEventsPass.php | 56 +++------- .../EventTransformer.php | 69 ++++-------- .../PhpSerializerEventTransformer.php | 27 +---- .../Tests/AsyncListenerTest.php | 8 +- pkg/async-event-dispatcher/composer.json | 14 +-- .../Profiler/MessageQueueCollector.php | 26 +---- .../Tests/Functional/App/AsyncListener.php | 33 ++---- .../App/TestAsyncEventTransformer.php | 102 +++++------------- .../Functional/App/config/config-sf5.yml | 6 +- pkg/enqueue-bundle/composer.json | 8 +- pkg/enqueue/composer.json | 18 ++-- pkg/fs/composer.json | 6 +- pkg/job-queue/composer.json | 8 +- pkg/simple-client/composer.json | 4 +- 20 files changed, 151 insertions(+), 395 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4854df188..35e32c10f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,11 +78,9 @@ jobs: fail-fast: false matrix: php: ['7.3', '7.4', '8.0'] - symfony_version: ['4.4.*', '5.2.*', '6.0.*'] + symfony_version: ['5.2.*', '6.0.*'] dependencies: ['--prefer-lowest', '--prefer-dist'] exclude: - - php: '8.0' - symfony_version: '4.4.*' - php: '7.3' symfony_version: '6.0.*' - php: '7.4' @@ -126,12 +124,10 @@ jobs: fail-fast: false matrix: php: ['7.4', '8.0'] # same as in the container - symfony_version: ['4.4.*', '5.2.*', '6.0.*'] + symfony_version: ['5.2.*', '6.0.*'] dependencies: ['--prefer-lowest', '--prefer-dist'] rdkafka_action: ['exclude-group', 'group'] exclude: - - php: '8.0' - symfony_version: '4.4.*' - php: '7.3' symfony_version: '6.0.*' - php: '7.4' diff --git a/composer.json b/composer.json index fe4e5570f..d4aa772c4 100644 --- a/composer.json +++ b/composer.json @@ -53,17 +53,17 @@ "phpunit/phpunit": "^9.5", "phpstan/phpstan": "^0.12", "queue-interop/queue-spec": "^0.6.2", - "symfony/browser-kit": "^4.3|^5|^6.0", - "symfony/config": "^4.3|^5|^6.0", - "symfony/process": "^4.3|^5|^6.0", - "symfony/console": "^4.3|^5|^6.0", - "symfony/dependency-injection": "^4.3|^5|^6.0", - "symfony/event-dispatcher": "^4.3|^5|^6.0", - "symfony/expression-language": "^4.3|^5|^6.0", - "symfony/http-kernel": "^4.3|^5|^6.0", - "symfony/filesystem": "^4.3|^5|^6.0", - "symfony/framework-bundle": "^4.3|^5|^6.0", - "symfony/yaml": "^4.3|^5|^6.0", + "symfony/browser-kit": "^5.1|^6.0", + "symfony/config": "^5.1|^6.0", + "symfony/process": "^5.1|^6.0", + "symfony/console": "^5.1|^6.0", + "symfony/dependency-injection": "^5.1|^6.0", + "symfony/event-dispatcher": "^5.1|^6.0", + "symfony/expression-language": "^5.1|^6.0", + "symfony/http-kernel": "^5.1|^6.0", + "symfony/filesystem": "^5.1|^6.0", + "symfony/framework-bundle": "^5.1|^6.0", + "symfony/yaml": "^5.1|^6.0", "empi89/php-amqp-stubs": "*@dev", "doctrine/doctrine-bundle": "^2.0", "doctrine/mongodb-odm-bundle": "^3.5|^4.3", diff --git a/docs/bundle/async_events.md b/docs/bundle/async_events.md index 99b674a76..d2d256146 100644 --- a/docs/bundle/async_events.md +++ b/docs/bundle/async_events.md @@ -39,7 +39,7 @@ enqueue: ## Usage -To make your listener async you have add `async: true` (every version) and `dispatcher: 'enqueue.events.event_dispatcher'` (since Symfony 5.3) attributes to the tag `kernel.event_listener`, like this: +To make your listener async you have add `async: true` and `dispatcher: 'enqueue.events.event_dispatcher'` attributes to the tag `kernel.event_listener`, like this: ```yaml # app/config/config.yml diff --git a/pkg/async-command/composer.json b/pkg/async-command/composer.json index 932499ecf..98b90ad83 100644 --- a/pkg/async-command/composer.json +++ b/pkg/async-command/composer.json @@ -9,16 +9,16 @@ "php": "^7.3|^8.0", "enqueue/enqueue": "^0.10", "queue-interop/queue-interop": "^0.8", - "symfony/console": "^4.3|^5|^6.0", - "symfony/process": "^4.3|^5|^6.0" + "symfony/console": "^5.1|^6.0", + "symfony/process": "^5.1|^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", - "symfony/dependency-injection": "^4.3|^5|^6.0", - "symfony/config": "^4.3|^5|^6.0", - "symfony/http-kernel": "^4.3|^5|^6.0", - "symfony/filesystem": "^4.3|^5|^6.0", - "symfony/yaml": "^4.3|^5|^6.0", + "symfony/dependency-injection": "^5.1|^6.0", + "symfony/config": "^5.1|^6.0", + "symfony/http-kernel": "^5.1|^6.0", + "symfony/filesystem": "^5.1|^6.0", + "symfony/yaml": "^5.1|^6.0", "enqueue/null": "0.10.x-dev", "enqueue/fs": "0.10.x-dev", "enqueue/test": "0.10.x-dev" @@ -31,7 +31,7 @@ "docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md" }, "suggest": { - "symfony/dependency-injection": "^4.3|^5|^6.0 If you'd like to use async event dispatcher container extension." + "symfony/dependency-injection": "^5.1|^6.0 If you'd like to use async event dispatcher container extension." }, "autoload": { "psr-4": { "Enqueue\\AsyncCommand\\": "" }, diff --git a/pkg/async-event-dispatcher/AsyncEventDispatcher.php b/pkg/async-event-dispatcher/AsyncEventDispatcher.php index 153fdc111..fa7393ea6 100644 --- a/pkg/async-event-dispatcher/AsyncEventDispatcher.php +++ b/pkg/async-event-dispatcher/AsyncEventDispatcher.php @@ -2,48 +2,17 @@ namespace Enqueue\AsyncEventDispatcher; -use Symfony\Component\EventDispatcher\Event; - -if (class_exists(Event::class)) { - /** - * Symfony < 5.0. - */ - class AsyncEventDispatcher extends AbstractAsyncEventDispatcher +class AsyncEventDispatcher extends AbstractAsyncEventDispatcher +{ + public function dispatch(object $event, string $eventName = null): object { - /** - * {@inheritdoc} - */ - public function dispatch($event, $eventName = null) - { - $this->parentDispatch($event, $eventName); - - return $this->trueEventDispatcher->dispatch($event, $eventName); - } + $this->parentDispatch($event, $eventName); - protected function parentDispatch($event, $eventName) - { - parent::dispatch($event, $eventName); - } + return $this->trueEventDispatcher->dispatch($event, $eventName); } -} else { - /** - * Symfony >= 5.0. - */ - class AsyncEventDispatcher extends AbstractAsyncEventDispatcher - { - /** - * {@inheritdoc} - */ - public function dispatch(object $event, string $eventName = null): object - { - $this->parentDispatch($event, $eventName); - return $this->trueEventDispatcher->dispatch($event, $eventName); - } - - protected function parentDispatch($event, $eventName) - { - return parent::dispatch($event, $eventName); - } + protected function parentDispatch($event, $eventName) + { + return parent::dispatch($event, $eventName); } } diff --git a/pkg/async-event-dispatcher/AsyncListener.php b/pkg/async-event-dispatcher/AsyncListener.php index ccbe5b038..2be4976fb 100644 --- a/pkg/async-event-dispatcher/AsyncListener.php +++ b/pkg/async-event-dispatcher/AsyncListener.php @@ -2,66 +2,28 @@ namespace Enqueue\AsyncEventDispatcher; -use Symfony\Component\EventDispatcher\Event; -use Symfony\Contracts\EventDispatcher\Event as ContractEvent; +use Symfony\Contracts\EventDispatcher\Event; -if (class_exists(Event::class)) { - /** - * Symfony < 5.0. - */ - class AsyncListener extends AbstractAsyncListener +class AsyncListener extends AbstractAsyncListener +{ + public function __invoke(Event $event, $eventName) { - /** - * @param Event|ContractEvent $event - * @param string $eventName - */ - public function __invoke($event, $eventName) - { - $this->onEvent($event, $eventName); - } - - /** - * @param Event|ContractEvent $event - * @param string $eventName - */ - public function onEvent($event, $eventName) - { - if (false == isset($this->syncMode[$eventName])) { - $transformerName = $this->registry->getTransformerNameForEvent($eventName); - - $message = $this->registry->getTransformer($transformerName)->toMessage($eventName, $event); - $message->setProperty('event_name', $eventName); - $message->setProperty('transformer_name', $transformerName); - - $this->context->createProducer()->send($this->eventQueue, $message); - } - } + $this->onEvent($event, $eventName); } -} else { + /** - * Symfony >= 5.0. + * @param string $eventName */ - class AsyncListener extends AbstractAsyncListener + public function onEvent(Event $event, $eventName) { - public function __invoke(ContractEvent $event, $eventName) - { - $this->onEvent($event, $eventName); - } - - /** - * @param string $eventName - */ - public function onEvent(ContractEvent $event, $eventName) - { - if (false == isset($this->syncMode[$eventName])) { - $transformerName = $this->registry->getTransformerNameForEvent($eventName); + if (false == isset($this->syncMode[$eventName])) { + $transformerName = $this->registry->getTransformerNameForEvent($eventName); - $message = $this->registry->getTransformer($transformerName)->toMessage($eventName, $event); - $message->setProperty('event_name', $eventName); - $message->setProperty('transformer_name', $transformerName); + $message = $this->registry->getTransformer($transformerName)->toMessage($eventName, $event); + $message->setProperty('event_name', $eventName); + $message->setProperty('transformer_name', $transformerName); - $this->context->createProducer()->send($this->eventQueue, $message); - } + $this->context->createProducer()->send($this->eventQueue, $message); } } } diff --git a/pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php b/pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php index e57d710f7..5eecd09ea 100644 --- a/pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php +++ b/pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php @@ -22,9 +22,6 @@ public function process(ContainerBuilder $container): void $defaultClient = $container->getParameter('enqueue.default_client'); - // TODO: Remove when dropping Symfony < 5.3 - $useLegacyDispatcherConfig = (Kernel::VERSION_ID < 50300); - $registeredToEvent = []; foreach ($container->findTaggedServiceIds('kernel.event_listener') as $serviceId => $tagAttributes) { foreach ($tagAttributes as $tagAttribute) { @@ -34,13 +31,6 @@ public function process(ContainerBuilder $container): void $event = $tagAttribute['event']; - $service = $container->getDefinition($serviceId); - - if ($useLegacyDispatcherConfig) { - $service->clearTag('kernel.event_listener'); - $service->addTag('enqueue.async_event_listener', $tagAttribute); - } - if (false == isset($registeredToEvent[$event])) { $container->getDefinition('enqueue.events.async_listener') ->addTag('kernel.event_listener', [ @@ -49,15 +39,13 @@ public function process(ContainerBuilder $container): void ]) ; - if (!$useLegacyDispatcherConfig) { - $container->getDefinition('enqueue.events.async_listener') - ->addTag('kernel.event_listener', [ - 'event' => $event, - 'method' => 'onEvent', - 'dispatcher' => 'enqueue.events.event_dispatcher', - ]) - ; - } + $container->getDefinition('enqueue.events.async_listener') + ->addTag('kernel.event_listener', [ + 'event' => $event, + 'method' => 'onEvent', + 'dispatcher' => 'enqueue.events.event_dispatcher', + ]) + ; $container->getDefinition('enqueue.events.async_processor') ->addTag('enqueue.processor', [ @@ -79,11 +67,6 @@ public function process(ContainerBuilder $container): void $service = $container->getDefinition($serviceId); - if ($useLegacyDispatcherConfig) { - $service->clearTag('kernel.event_subscriber'); - $service->addTag('enqueue.async_event_subscriber', $tagAttribute); - } - /** @var EventSubscriberInterface $serviceClass */ $serviceClass = $service->getClass(); @@ -96,15 +79,13 @@ public function process(ContainerBuilder $container): void ]) ; - if (!$useLegacyDispatcherConfig) { - $container->getDefinition('enqueue.events.async_listener') - ->addTag('kernel.event_listener', [ - 'event' => $event, - 'method' => 'onEvent', - 'dispatcher' => 'enqueue.events.event_dispatcher', - ]) - ; - } + $container->getDefinition('enqueue.events.async_listener') + ->addTag('kernel.event_listener', [ + 'event' => $event, + 'method' => 'onEvent', + 'dispatcher' => 'enqueue.events.event_dispatcher', + ]) + ; $container->getDefinition('enqueue.events.async_processor') ->addTag('enqueue.processor', [ @@ -118,14 +99,5 @@ public function process(ContainerBuilder $container): void } } } - - if ($useLegacyDispatcherConfig) { - $registerListenersPass = new RegisterListenersPass( - 'enqueue.events.event_dispatcher', - 'enqueue.async_event_listener', - 'enqueue.async_event_subscriber' - ); - $registerListenersPass->process($container); - } } } diff --git a/pkg/async-event-dispatcher/EventTransformer.php b/pkg/async-event-dispatcher/EventTransformer.php index 352930cef..cee8635bd 100644 --- a/pkg/async-event-dispatcher/EventTransformer.php +++ b/pkg/async-event-dispatcher/EventTransformer.php @@ -3,61 +3,28 @@ namespace Enqueue\AsyncEventDispatcher; use Interop\Queue\Message; -use Symfony\Component\EventDispatcher\Event; -use Symfony\Contracts\EventDispatcher\Event as ContractEvent; +use Symfony\Contracts\EventDispatcher\Event; -if (class_exists(Event::class)) { +interface EventTransformer +{ /** - * Symfony < 5.0. + * @param string $eventName + * + * @return Message */ - interface EventTransformer - { - /** - * @param string $eventName - * @param ContractEvent|Event|null $event - * - * @return Message - */ - public function toMessage($eventName, $event = null); + public function toMessage($eventName, Event $event = null); - /** - * If you able to transform message back to event return it. - * If you failed to transform for some reason you can return a string status. - * - * @param mixed $eventName - * - * @return ContractEvent|Event|string|object - * - * @see Process constants) or an object that implements __toString method. - * The object must have a __toString method is supposed to be used as Processor::process return value. - */ - public function toEvent($eventName, Message $message); - } -} else { /** - * Symfony >= 5.0. + * If you able to transform message back to event return it. + * If you failed to transform for some reason you can return a string status. + * + * @param mixed $eventNAme + * @param mixed $eventName + * + * @return Event|string|object + * + * @see Process constants) or an object that implements __toString method. + * The object must have a __toString method is supposed to be used as Processor::process return value. */ - interface EventTransformer - { - /** - * @param string $eventName - * - * @return Message - */ - public function toMessage($eventName, ContractEvent $event = null); - - /** - * If you able to transform message back to event return it. - * If you failed to transform for some reason you can return a string status. - * - * @param mixed $eventNAme - * @param mixed $eventName - * - * @return ContractEvent|string|object - * - * @see Process constants) or an object that implements __toString method. - * The object must have a __toString method is supposed to be used as Processor::process return value. - */ - public function toEvent($eventName, Message $message); - } + public function toEvent($eventName, Message $message); } diff --git a/pkg/async-event-dispatcher/PhpSerializerEventTransformer.php b/pkg/async-event-dispatcher/PhpSerializerEventTransformer.php index c6a3e2c97..1204e9591 100644 --- a/pkg/async-event-dispatcher/PhpSerializerEventTransformer.php +++ b/pkg/async-event-dispatcher/PhpSerializerEventTransformer.php @@ -2,29 +2,12 @@ namespace Enqueue\AsyncEventDispatcher; -use Symfony\Component\EventDispatcher\Event; -use Symfony\Contracts\EventDispatcher\Event as ContractEvent; +use Symfony\Contracts\EventDispatcher\Event; -if (class_exists(Event::class)) { - /** - * Symfony < 5.0. - */ - class PhpSerializerEventTransformer extends AbstractPhpSerializerEventTransformer implements EventTransformer +class PhpSerializerEventTransformer extends AbstractPhpSerializerEventTransformer implements EventTransformer +{ + public function toMessage($eventName, Event $event = null) { - public function toMessage($eventName, $event = null) - { - return $this->context->createMessage(serialize($event)); - } - } -} else { - /** - * Symfony >= 5.0. - */ - class PhpSerializerEventTransformer extends AbstractPhpSerializerEventTransformer implements EventTransformer - { - public function toMessage($eventName, ContractEvent $event = null) - { - return $this->context->createMessage(serialize($event)); - } + return $this->context->createMessage(serialize($event)); } } diff --git a/pkg/async-event-dispatcher/Tests/AsyncListenerTest.php b/pkg/async-event-dispatcher/Tests/AsyncListenerTest.php index f00635245..d888c0228 100644 --- a/pkg/async-event-dispatcher/Tests/AsyncListenerTest.php +++ b/pkg/async-event-dispatcher/Tests/AsyncListenerTest.php @@ -13,10 +13,8 @@ use Interop\Queue\Producer; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\GenericEvent; -use Symfony\Component\HttpKernel\Kernel; -use Symfony\Contracts\EventDispatcher\Event as ContractEvent; +use Symfony\Contracts\EventDispatcher\Event; class AsyncListenerTest extends TestCase { @@ -73,9 +71,7 @@ public function testShouldDoNothingIfSyncModeOn() $listener->syncMode('fooEvent'); - $eventClass = Kernel::VERSION_ID >= 50000 ? ContractEvent::class : Event::class; - - $listener->onEvent(new $eventClass(), 'fooEvent'); + $listener->onEvent(new Event(), 'fooEvent'); $listener->onEvent(new GenericEvent(), 'fooEvent'); } diff --git a/pkg/async-event-dispatcher/composer.json b/pkg/async-event-dispatcher/composer.json index 28ed42b4f..3f124dc8f 100644 --- a/pkg/async-event-dispatcher/composer.json +++ b/pkg/async-event-dispatcher/composer.json @@ -9,15 +9,15 @@ "php": "^7.3|^8.0", "enqueue/enqueue": "^0.10", "queue-interop/queue-interop": "^0.8", - "symfony/event-dispatcher": "^4.3|^5|^6.0" + "symfony/event-dispatcher": "^5.1|^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", - "symfony/dependency-injection": "^4.3|^5|^6.0", - "symfony/config": "^4.3|^5|^6.0", - "symfony/http-kernel": "^4.3|^5|^6.0", - "symfony/filesystem": "^4.3|^5|^6.0", - "symfony/yaml": "^4.3|^5|^6.0", + "symfony/dependency-injection": "^5.1|^6.0", + "symfony/config": "^5.1|^6.0", + "symfony/http-kernel": "^5.1|^6.0", + "symfony/filesystem": "^5.1|^6.0", + "symfony/yaml": "^5.1|^6.0", "enqueue/null": "0.10.x-dev", "enqueue/fs": "0.10.x-dev", "enqueue/test": "0.10.x-dev" @@ -30,7 +30,7 @@ "docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md" }, "suggest": { - "symfony/dependency-injection": "^2.8|^3|^4|^5 If you'd like to use async event dispatcher container extension." + "symfony/dependency-injection": "^5.1|^6.0 If you'd like to use async event dispatcher container extension." }, "autoload": { "psr-4": { "Enqueue\\AsyncEventDispatcher\\": "" }, diff --git a/pkg/enqueue-bundle/Profiler/MessageQueueCollector.php b/pkg/enqueue-bundle/Profiler/MessageQueueCollector.php index e44429413..7fc6699c5 100644 --- a/pkg/enqueue-bundle/Profiler/MessageQueueCollector.php +++ b/pkg/enqueue-bundle/Profiler/MessageQueueCollector.php @@ -4,28 +4,12 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Kernel; +use Throwable; -if (Kernel::MAJOR_VERSION < 5) { - class MessageQueueCollector extends AbstractMessageQueueCollector +class MessageQueueCollector extends AbstractMessageQueueCollector +{ + public function collect(Request $request, Response $response, Throwable $exception = null) { - /** - * {@inheritdoc} - */ - public function collect(Request $request, Response $response, \Exception $exception = null) - { - $this->collectInternal($request, $response); - } - } -} else { - class MessageQueueCollector extends AbstractMessageQueueCollector - { - /** - * {@inheritdoc} - */ - public function collect(Request $request, Response $response, \Throwable $exception = null) - { - $this->collectInternal($request, $response); - } + $this->collectInternal($request, $response); } } diff --git a/pkg/enqueue-bundle/Tests/Functional/App/AsyncListener.php b/pkg/enqueue-bundle/Tests/Functional/App/AsyncListener.php index 2248dc5d1..23ab4af79 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/AsyncListener.php +++ b/pkg/enqueue-bundle/Tests/Functional/App/AsyncListener.php @@ -2,36 +2,15 @@ namespace Enqueue\Bundle\Tests\Functional\App; -use Symfony\Component\EventDispatcher\Event; -use Symfony\Contracts\EventDispatcher\Event as ContractEvent; +use Symfony\Contracts\EventDispatcher\Event; -if (class_exists(Event::class)) { +class AsyncListener extends AbstractAsyncListener +{ /** - * Symfony < 5.0. + * @param string $eventName */ - class AsyncListener extends AbstractAsyncListener + public function onEvent(Event $event, $eventName) { - /** - * @param Event|ContractEvent $event - * @param string $eventName - */ - public function onEvent($event, $eventName) - { - $this->onEventInternal($event, $eventName); - } - } -} else { - /** - * Symfony >= 5.0. - */ - class AsyncListener extends AbstractAsyncListener - { - /** - * @param string $eventName - */ - public function onEvent(ContractEvent $event, $eventName) - { - $this->onEventInternal($event, $eventName); - } + $this->onEventInternal($event, $eventName); } } diff --git a/pkg/enqueue-bundle/Tests/Functional/App/TestAsyncEventTransformer.php b/pkg/enqueue-bundle/Tests/Functional/App/TestAsyncEventTransformer.php index 7c85e076c..2a734682d 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/TestAsyncEventTransformer.php +++ b/pkg/enqueue-bundle/Tests/Functional/App/TestAsyncEventTransformer.php @@ -6,96 +6,46 @@ use Enqueue\Util\JSON; use Interop\Queue\Context; use Interop\Queue\Message; -use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\GenericEvent; -use Symfony\Contracts\EventDispatcher\Event as ContractEvent; +use Symfony\Contracts\EventDispatcher\Event; -if (class_exists(Event::class)) { +class TestAsyncEventTransformer implements EventTransformer +{ /** - * Symfony < 5.0. + * @var Context */ - class TestAsyncEventTransformer implements EventTransformer + private $context; + + public function __construct(Context $context) { - /** - * @var Context - */ - private $context; + $this->context = $context; + } - public function __construct(Context $context) - { - $this->context = $context; + public function toMessage($eventName, Event $event = null) + { + if (Event::class === get_class($event)) { + return $this->context->createMessage(json_encode('')); } - public function toMessage($eventName, $event = null) - { - if (Event::class === get_class($event) || ContractEvent::class === get_class($event)) { - return $this->context->createMessage(json_encode('')); - } - - /** @var GenericEvent $event */ - if (false == $event instanceof GenericEvent) { - throw new \LogicException('Must be GenericEvent'); - } - - return $this->context->createMessage(json_encode([ - 'subject' => $event->getSubject(), - 'arguments' => $event->getArguments(), - ])); + /** @var GenericEvent $event */ + if (false == $event instanceof GenericEvent) { + throw new \LogicException('Must be GenericEvent'); } - public function toEvent($eventName, Message $message) - { - $data = JSON::decode($message->getBody()); - - if ('' === $data) { - return new Event(); - } - - return new GenericEvent($data['subject'], $data['arguments']); - } + return $this->context->createMessage(json_encode([ + 'subject' => $event->getSubject(), + 'arguments' => $event->getArguments(), + ])); } -} else { - /** - * Symfony >= 5.0. - */ - class TestAsyncEventTransformer implements EventTransformer - { - /** - * @var Context - */ - private $context; - - public function __construct(Context $context) - { - $this->context = $context; - } - - public function toMessage($eventName, ContractEvent $event = null) - { - if (ContractEvent::class === get_class($event)) { - return $this->context->createMessage(json_encode('')); - } - /** @var GenericEvent $event */ - if (false == $event instanceof GenericEvent) { - throw new \LogicException('Must be GenericEvent'); - } + public function toEvent($eventName, Message $message) + { + $data = JSON::decode($message->getBody()); - return $this->context->createMessage(json_encode([ - 'subject' => $event->getSubject(), - 'arguments' => $event->getArguments(), - ])); + if ('' === $data) { + return new Event(); } - public function toEvent($eventName, Message $message) - { - $data = JSON::decode($message->getBody()); - - if ('' === $data) { - return new ContractEvent(); - } - - return new GenericEvent($data['subject'], $data['arguments']); - } + return new GenericEvent($data['subject'], $data['arguments']); } } diff --git a/pkg/enqueue-bundle/Tests/Functional/App/config/config-sf5.yml b/pkg/enqueue-bundle/Tests/Functional/App/config/config-sf5.yml index 3a4f7795d..e202bb86f 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/config/config-sf5.yml +++ b/pkg/enqueue-bundle/Tests/Functional/App/config/config-sf5.yml @@ -87,8 +87,7 @@ services: class: 'Enqueue\Bundle\Tests\Functional\App\TestAsyncListener' public: true tags: - - { name: 'kernel.event_listener', async: true, event: 'test_async', method: 'onEvent' } - # In Symfony 6 you would also add "dispatcher: 'enqueue.events.event_dispatcher'" + - { name: 'kernel.event_listener', async: true, event: 'test_async', method: 'onEvent', dispatcher: 'enqueue.events.event_dispatcher' } test_command_subscriber_processor: class: 'Enqueue\Bundle\Tests\Functional\App\TestCommandSubscriberProcessor' @@ -112,8 +111,7 @@ services: class: 'Enqueue\Bundle\Tests\Functional\App\TestAsyncSubscriber' public: true tags: - - { name: 'kernel.event_subscriber', async: true } - # In Symfony 6 you would also add "dispatcher: 'enqueue.events.event_dispatcher'" + - { name: 'kernel.event_subscriber', async: true, dispatcher: 'enqueue.events.event_dispatcher' } test_async_event_transformer: class: 'Enqueue\Bundle\Tests\Functional\App\TestAsyncEventTransformer' diff --git a/pkg/enqueue-bundle/composer.json b/pkg/enqueue-bundle/composer.json index 70eda07bd..ab4ed1e4f 100644 --- a/pkg/enqueue-bundle/composer.json +++ b/pkg/enqueue-bundle/composer.json @@ -7,7 +7,7 @@ "license": "MIT", "require": { "php": "^7.3|^8.0", - "symfony/framework-bundle": "^4.3|^5|^6.0", + "symfony/framework-bundle": "^5.1|^6.0", "queue-interop/amqp-interop": "^0.8.2", "queue-interop/queue-interop": "^0.8", "enqueue/enqueue": "^0.10", @@ -39,9 +39,9 @@ "doctrine/doctrine-bundle": "^2.0", "doctrine/mongodb-odm-bundle": "^3.5|^4.3", "alcaeus/mongo-php-adapter": "^1.0", - "symfony/browser-kit": "^4.3|^5|^6.0", - "symfony/expression-language": "^4.3|^5|^6.0", - "symfony/yaml": "^4.3|^5|^6.0" + "symfony/browser-kit": "^5.1|^6.0", + "symfony/expression-language": "^5.1|^6.0", + "symfony/yaml": "^5.1|^6.0" }, "suggest": { "enqueue/async-command": "If want to run Symfony command via message queue", diff --git a/pkg/enqueue/composer.json b/pkg/enqueue/composer.json index 82c77527e..0798bf44e 100644 --- a/pkg/enqueue/composer.json +++ b/pkg/enqueue/composer.json @@ -17,12 +17,12 @@ }, "require-dev": { "phpunit/phpunit": "^9.5", - "symfony/console": "^4.3|^5|^6.0", - "symfony/dependency-injection": "^4.3|^5|^6.0", - "symfony/config": "^4.3|^5|^6.0", - "symfony/event-dispatcher": "^4.3|^5|^6.0", - "symfony/http-kernel": "^4.3|^5|^6.0", - "symfony/yaml": "^4.3|^5|^6.0", + "symfony/console": "^5.1|^6.0", + "symfony/dependency-injection": "^5.1|^6.0", + "symfony/config": "^5.1|^6.0", + "symfony/event-dispatcher": "^5.1|^6.0", + "symfony/http-kernel": "^5.1|^6.0", + "symfony/yaml": "^5.1|^6.0", "enqueue/amqp-ext": "0.10.x-dev", "enqueue/amqp-lib": "0.10.x-dev", "enqueue/amqp-bunny": "0.10.x-dev", @@ -42,9 +42,9 @@ "enqueue/dsn": "0.10.x-dev" }, "suggest": { - "symfony/console": "^2.8|^3|^4|^5|^6.0 If you want to use cli commands", - "symfony/dependency-injection": "^4.3|^5|^6.0", - "symfony/config": "^4.3|^5|^6.0", + "symfony/console": "^5.1|^6.0 If you want to use cli commands", + "symfony/dependency-injection": "^5.1|^6.0", + "symfony/config": "^5.1|^6.0", "enqueue/amqp-ext": "AMQP transport (based on php extension)", "enqueue/stomp": "STOMP transport", "enqueue/fs": "Filesystem transport", diff --git a/pkg/fs/composer.json b/pkg/fs/composer.json index 193d603d3..e22929097 100644 --- a/pkg/fs/composer.json +++ b/pkg/fs/composer.json @@ -9,7 +9,7 @@ "php": "^7.3|^8.0", "queue-interop/queue-interop": "^0.8", "enqueue/dsn": "^0.10", - "symfony/filesystem": "^4.3|^5|^6.0", + "symfony/filesystem": "^5.1|^6.0", "makasim/temp-file": "^0.2@stable" }, "require-dev": { @@ -17,8 +17,8 @@ "enqueue/null": "0.10.x-dev", "enqueue/test": "0.10.x-dev", "queue-interop/queue-spec": "^0.6.2", - "symfony/dependency-injection": "^4.3|^5|^6.0", - "symfony/yaml": "^4.3|^5|^6.0" + "symfony/dependency-injection": "^5.1|^6.0", + "symfony/yaml": "^5.1|^6.0" }, "support": { "email": "opensource@forma-pro.com", diff --git a/pkg/job-queue/composer.json b/pkg/job-queue/composer.json index 998245e4b..d4d1fe706 100644 --- a/pkg/job-queue/composer.json +++ b/pkg/job-queue/composer.json @@ -17,10 +17,10 @@ "phpunit/phpunit": "^9.5", "enqueue/test": "0.10.x-dev", "doctrine/doctrine-bundle": "^2.0", - "symfony/browser-kit": "^4.3|^5|^6.0", - "symfony/expression-language": "^4.3|^5|^6.0", - "symfony/framework-bundle": "^4.3|^5|^6.0", - "symfony/yaml": "^4.3|^5|^6.0" + "symfony/browser-kit": "^5.1|^6.0", + "symfony/expression-language": "^5.1|^6.0", + "symfony/framework-bundle": "^5.1|^6.0", + "symfony/yaml": "^5.1|^6.0" }, "support": { "email": "opensource@forma-pro.com", diff --git a/pkg/simple-client/composer.json b/pkg/simple-client/composer.json index 037bf3fcd..f12215eac 100644 --- a/pkg/simple-client/composer.json +++ b/pkg/simple-client/composer.json @@ -10,7 +10,7 @@ "enqueue/enqueue": "^0.10", "queue-interop/amqp-interop": "^0.8.2", "queue-interop/queue-interop": "^0.8", - "symfony/config": "^4.3|^5|^6.0" + "symfony/config": "^5.1|^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", @@ -18,7 +18,7 @@ "enqueue/amqp-ext": "0.10.x-dev", "enqueue/fs": "0.10.x-dev", "enqueue/null": "0.10.x-dev", - "symfony/yaml": "^4.3|^5|^6.0" + "symfony/yaml": "^5.1|^6.0" }, "support": { "email": "opensource@forma-pro.com", From dc3f0d62b8fcf5fe4ace2e0067d9fbf7597a93a4 Mon Sep 17 00:00:00 2001 From: Andrew M-Y Date: Wed, 16 Feb 2022 13:18:28 +0200 Subject: [PATCH 6/6] Remove unused uses --- .../DependencyInjection/AsyncEventsPass.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php b/pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php index 5eecd09ea..42774adf7 100644 --- a/pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php +++ b/pkg/async-event-dispatcher/DependencyInjection/AsyncEventsPass.php @@ -4,9 +4,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpKernel\Kernel; class AsyncEventsPass implements CompilerPassInterface {