From 4492e2112f08d369daf5cc59aa8e358b54409e1b Mon Sep 17 00:00:00 2001 From: Viktor Zavitkov Date: Thu, 14 Nov 2024 13:08:33 +0300 Subject: [PATCH 1/9] add symfony 7 support --- .github/workflows/ci.yml | 30 ++++++------------------------ pkg/enqueue-bundle/composer.json | 17 +++++++++++------ 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c29d8430c..21cc407be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: - uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: '8.2' coverage: none extensions: mongodb, redis, :xdebug ini-values: memory_limit=2048M @@ -77,18 +77,9 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.4', '8.0', '8.1', '8.2'] - symfony_version: ['5.4.*', '6.2.*', '6.3.*'] + php: ['8.1', '8.2'] + symfony_version: ['6.2.*', '6.3.*', '6.4.*', '7.0.*'] dependencies: ['--prefer-lowest', '--prefer-dist'] - exclude: - - php: '7.4' - symfony_version: '6.2.*' - - php: '7.4' - symfony_version: '6.3.*' - - php: '8.0' - symfony_version: '6.2.*' - - php: '8.0' - symfony_version: '6.3.*' name: PHP ${{ matrix.php }} unit tests on Sf ${{ matrix.symfony_version }}, deps=${{ matrix.dependencies }} @@ -127,18 +118,9 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.4', '8.0', '8.1', '8.2'] # same as in the container - symfony_version: ['5.4.*', '6.2.*', '6.3.*'] - dependencies: ['--prefer-lowest', '--prefer-dist'] - exclude: - - php: '7.4' - symfony_version: '6.2.*' - - php: '7.4' - symfony_version: '6.3.*' - - php: '8.0' - symfony_version: '6.2.*' - - php: '8.0' - symfony_version: '6.3.*' + php: [ '8.1', '8.2' ] + symfony_version: [ '6.2.*', '6.3.*', '6.4.*', '7.0.*' ] + dependencies: [ '--prefer-lowest', '--prefer-dist' ] name: PHP ${{ matrix.php }} functional tests on Sf ${{ matrix.symfony_version }}, deps=${{ matrix.dependencies }} diff --git a/pkg/enqueue-bundle/composer.json b/pkg/enqueue-bundle/composer.json index 7ee50c269..1a070ee50 100644 --- a/pkg/enqueue-bundle/composer.json +++ b/pkg/enqueue-bundle/composer.json @@ -6,8 +6,8 @@ "homepage": "https://enqueue.forma-pro.com/", "license": "MIT", "require": { - "php": "^7.4|^8.0", - "symfony/framework-bundle": "^5.4|^6.0", + "php": "^8.1", + "symfony/framework-bundle": "^6.2|^7.0", "queue-interop/amqp-interop": "^0.8.2", "queue-interop/queue-interop": "^0.8", "enqueue/enqueue": "^0.10", @@ -39,10 +39,10 @@ "doctrine/doctrine-bundle": "^2.3.2", "doctrine/mongodb-odm-bundle": "^3.5|^4.3", "alcaeus/mongo-php-adapter": "^1.0", - "symfony/browser-kit": "^5.4|^6.0", - "symfony/expression-language": "^5.4|^6.0", - "symfony/validator": "^5.4|^6.0", - "symfony/yaml": "^5.4|^6.0" + "symfony/browser-kit": "^6.2|^7.0", + "symfony/expression-language": "^6.2|^7.0", + "symfony/validator": "^6.2|^7.0", + "symfony/yaml": "^6.2|^7.0" }, "suggest": { "enqueue/async-command": "If want to run Symfony command via message queue", @@ -58,5 +58,10 @@ "branch-alias": { "dev-master": "0.10.x-dev" } + }, + "config": { + "allow-plugins": { + "php-http/discovery": true + } } } From 15a98812a355601fafab7b2a09cf0f6677f7ceba Mon Sep 17 00:00:00 2001 From: Viktor Zavitkov Date: Thu, 14 Nov 2024 13:22:17 +0300 Subject: [PATCH 2/9] fix deprecations --- pkg/enqueue/Doctrine/DoctrineSchemaCompilerPass.php | 2 +- pkg/enqueue/Symfony/Client/ConsumeCommand.php | 2 -- pkg/enqueue/Symfony/Client/ProduceCommand.php | 2 -- pkg/enqueue/Symfony/Client/RoutesCommand.php | 2 -- pkg/enqueue/Symfony/Client/SetupBrokerCommand.php | 2 -- pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php | 2 -- pkg/enqueue/Symfony/Consumption/ConsumeCommand.php | 2 -- 7 files changed, 1 insertion(+), 13 deletions(-) diff --git a/pkg/enqueue/Doctrine/DoctrineSchemaCompilerPass.php b/pkg/enqueue/Doctrine/DoctrineSchemaCompilerPass.php index 25016a761..0eb378470 100644 --- a/pkg/enqueue/Doctrine/DoctrineSchemaCompilerPass.php +++ b/pkg/enqueue/Doctrine/DoctrineSchemaCompilerPass.php @@ -11,7 +11,7 @@ class DoctrineSchemaCompilerPass implements CompilerPassInterface { - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (false === $container->hasDefinition('doctrine')) { return; diff --git a/pkg/enqueue/Symfony/Client/ConsumeCommand.php b/pkg/enqueue/Symfony/Client/ConsumeCommand.php index 39af6d592..c97dd3a33 100644 --- a/pkg/enqueue/Symfony/Client/ConsumeCommand.php +++ b/pkg/enqueue/Symfony/Client/ConsumeCommand.php @@ -28,8 +28,6 @@ class ConsumeCommand extends Command use QueueConsumerOptionsCommandTrait; use SetupBrokerExtensionCommandTrait; - protected static $defaultName = 'enqueue:consume'; - /** * @var ContainerInterface */ diff --git a/pkg/enqueue/Symfony/Client/ProduceCommand.php b/pkg/enqueue/Symfony/Client/ProduceCommand.php index 6064f82e1..512dd5f25 100644 --- a/pkg/enqueue/Symfony/Client/ProduceCommand.php +++ b/pkg/enqueue/Symfony/Client/ProduceCommand.php @@ -16,8 +16,6 @@ #[AsCommand('enqueue:produce')] class ProduceCommand extends Command { - protected static $defaultName = 'enqueue:produce'; - /** * @var ContainerInterface */ diff --git a/pkg/enqueue/Symfony/Client/RoutesCommand.php b/pkg/enqueue/Symfony/Client/RoutesCommand.php index 59a4a4d98..99979d5c1 100644 --- a/pkg/enqueue/Symfony/Client/RoutesCommand.php +++ b/pkg/enqueue/Symfony/Client/RoutesCommand.php @@ -17,8 +17,6 @@ #[AsCommand('enqueue:routes')] class RoutesCommand extends Command { - protected static $defaultName = 'enqueue:routes'; - /** * @var ContainerInterface */ diff --git a/pkg/enqueue/Symfony/Client/SetupBrokerCommand.php b/pkg/enqueue/Symfony/Client/SetupBrokerCommand.php index 68aebb582..78bb4041d 100644 --- a/pkg/enqueue/Symfony/Client/SetupBrokerCommand.php +++ b/pkg/enqueue/Symfony/Client/SetupBrokerCommand.php @@ -15,8 +15,6 @@ #[AsCommand('enqueue:setup-broker')] class SetupBrokerCommand extends Command { - protected static $defaultName = 'enqueue:setup-broker'; - /** * @var ContainerInterface */ diff --git a/pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php b/pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php index 234eb0497..2847ca569 100644 --- a/pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php +++ b/pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php @@ -22,8 +22,6 @@ class ConfigurableConsumeCommand extends Command use LimitsExtensionsCommandTrait; use QueueConsumerOptionsCommandTrait; - protected static $defaultName = 'enqueue:transport:consume'; - /** * @var ContainerInterface */ diff --git a/pkg/enqueue/Symfony/Consumption/ConsumeCommand.php b/pkg/enqueue/Symfony/Consumption/ConsumeCommand.php index 870cc5f60..c8de790b8 100644 --- a/pkg/enqueue/Symfony/Consumption/ConsumeCommand.php +++ b/pkg/enqueue/Symfony/Consumption/ConsumeCommand.php @@ -20,8 +20,6 @@ class ConsumeCommand extends Command use LimitsExtensionsCommandTrait; use QueueConsumerOptionsCommandTrait; - protected static $defaultName = 'enqueue:transport:consume'; - /** * @var ContainerInterface */ From 828bd2f818561e0f0db581b1735db9505e5791cd Mon Sep 17 00:00:00 2001 From: Viktor Zavitkov Date: Thu, 14 Nov 2024 15:04:57 +0300 Subject: [PATCH 3/9] fix tests --- .../Symfony/Client/ConsumeCommandTest.php | 20 +++++++++++++++---- .../Symfony/Client/ProduceCommandTest.php | 18 ++++++++++++++--- .../Symfony/Client/RoutesCommandTest.php | 18 ++++++++++++++--- .../Symfony/Client/SetupBrokerCommandTest.php | 18 ++++++++++++++--- .../Client/SimpleConsumeCommandTest.php | 7 ------- .../Client/SimpleProduceCommandTest.php | 7 ------- .../Client/SimpleRoutesCommandTest.php | 7 ------- .../Client/SimpleSetupBrokerCommandTest.php | 7 ------- .../ConfigurableConsumeCommandTest.php | 20 +++++++++++++++---- .../Consumption/ConsumeCommandTest.php | 20 +++++++++++++++---- .../Consumption/SimpleConsumeCommandTest.php | 7 ------- 11 files changed, 93 insertions(+), 56 deletions(-) diff --git a/pkg/enqueue/Tests/Symfony/Client/ConsumeCommandTest.php b/pkg/enqueue/Tests/Symfony/Client/ConsumeCommandTest.php index 1d94e6e51..8076aaf76 100644 --- a/pkg/enqueue/Tests/Symfony/Client/ConsumeCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Client/ConsumeCommandTest.php @@ -22,6 +22,7 @@ use Interop\Queue\Queue; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; @@ -44,11 +45,22 @@ public function testCouldBeConstructedWithRequiredAttributes() new ConsumeCommand($this->createMock(ContainerInterface::class), 'default'); } - public function testShouldHaveCommandName() + public function testShouldHaveAsCommandAttributeWithCommandName() { - $command = new ConsumeCommand($this->createMock(ContainerInterface::class), 'default'); + $commandClass = ConsumeCommand::class; + + $reflectionClass = new \ReflectionClass($commandClass); + + $attributes = $reflectionClass->getAttributes(AsCommand::class); + + $this->assertNotEmpty($attributes, 'The command does not have the AsCommand attribute.'); + + // Get the first attribute instance (assuming there is only one AsCommand attribute) + $asCommandAttribute = $attributes[0]; - $this->assertEquals('enqueue:consume', $command->getName()); + // Verify the 'name' parameter value + $attributeInstance = $asCommandAttribute->newInstance(); + $this->assertEquals('enqueue:consume', $attributeInstance->name, 'The command name is not set correctly in the AsCommand attribute.'); } public function testShouldHaveExpectedOptions() @@ -641,7 +653,7 @@ private function createContextWithoutSubscriptionConsumerMock(): InteropContext /** * @return \PHPUnit\Framework\MockObject\MockObject|InteropContext */ - private function createContextStub(Consumer $consumer = null): InteropContext + private function createContextStub(?Consumer $consumer = null): InteropContext { $context = $this->createContextWithoutSubscriptionConsumerMock(); $context diff --git a/pkg/enqueue/Tests/Symfony/Client/ProduceCommandTest.php b/pkg/enqueue/Tests/Symfony/Client/ProduceCommandTest.php index 0dffc3d42..2efc4769f 100644 --- a/pkg/enqueue/Tests/Symfony/Client/ProduceCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Client/ProduceCommandTest.php @@ -9,6 +9,7 @@ use Enqueue\Test\ClassExtensionTrait; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; @@ -31,11 +32,22 @@ public function testCouldBeConstructedWithContainerAsFirstArgument() new ProduceCommand($this->createMock(ContainerInterface::class), 'default'); } - public function testShouldHaveCommandName() + public function testShouldHaveAsCommandAttributeWithCommandName() { - $command = new ProduceCommand($this->createMock(ContainerInterface::class), 'default'); + $commandClass = ProduceCommand::class; + + $reflectionClass = new \ReflectionClass($commandClass); + + $attributes = $reflectionClass->getAttributes(AsCommand::class); + + $this->assertNotEmpty($attributes, 'The command does not have the AsCommand attribute.'); + + // Get the first attribute instance (assuming there is only one AsCommand attribute) + $asCommandAttribute = $attributes[0]; - $this->assertEquals('enqueue:produce', $command->getName()); + // Verify the 'name' parameter value + $attributeInstance = $asCommandAttribute->newInstance(); + $this->assertEquals('enqueue:produce', $attributeInstance->name, 'The command name is not set correctly in the AsCommand attribute.'); } public function testShouldHaveExpectedOptions() diff --git a/pkg/enqueue/Tests/Symfony/Client/RoutesCommandTest.php b/pkg/enqueue/Tests/Symfony/Client/RoutesCommandTest.php index 04980c135..c2168c4f8 100644 --- a/pkg/enqueue/Tests/Symfony/Client/RoutesCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Client/RoutesCommandTest.php @@ -11,6 +11,7 @@ use Enqueue\Test\ClassExtensionTrait; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; @@ -33,11 +34,22 @@ public function testCouldBeConstructedWithConfigAndRouteCollectionAsArguments() new RoutesCommand($this->createMock(ContainerInterface::class), 'default'); } - public function testShouldHaveCommandName() + public function testShouldHaveAsCommandAttributeWithCommandName() { - $command = new RoutesCommand($this->createMock(ContainerInterface::class), 'default'); + $commandClass = RoutesCommand::class; + + $reflectionClass = new \ReflectionClass($commandClass); + + $attributes = $reflectionClass->getAttributes(AsCommand::class); + + $this->assertNotEmpty($attributes, 'The command does not have the AsCommand attribute.'); + + // Get the first attribute instance (assuming there is only one AsCommand attribute) + $asCommandAttribute = $attributes[0]; - $this->assertEquals('enqueue:routes', $command->getName()); + // Verify the 'name' parameter value + $attributeInstance = $asCommandAttribute->newInstance(); + $this->assertEquals('enqueue:routes', $attributeInstance->name, 'The command name is not set correctly in the AsCommand attribute.'); } public function testShouldHaveCommandAliases() diff --git a/pkg/enqueue/Tests/Symfony/Client/SetupBrokerCommandTest.php b/pkg/enqueue/Tests/Symfony/Client/SetupBrokerCommandTest.php index 82345b2bf..89ca379b5 100644 --- a/pkg/enqueue/Tests/Symfony/Client/SetupBrokerCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Client/SetupBrokerCommandTest.php @@ -8,6 +8,7 @@ use Enqueue\Test\ClassExtensionTrait; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; @@ -30,11 +31,22 @@ public function testCouldBeConstructedWithContainerAsFirstArgument() new SetupBrokerCommand($this->createMock(ContainerInterface::class), 'default'); } - public function testShouldHaveCommandName() + public function testShouldHaveAsCommandAttributeWithCommandName() { - $command = new SetupBrokerCommand($this->createMock(ContainerInterface::class), 'default'); + $commandClass = SetupBrokerCommand::class; + + $reflectionClass = new \ReflectionClass($commandClass); + + $attributes = $reflectionClass->getAttributes(AsCommand::class); + + $this->assertNotEmpty($attributes, 'The command does not have the AsCommand attribute.'); + + // Get the first attribute instance (assuming there is only one AsCommand attribute) + $asCommandAttribute = $attributes[0]; - $this->assertEquals('enqueue:setup-broker', $command->getName()); + // Verify the 'name' parameter value + $attributeInstance = $asCommandAttribute->newInstance(); + $this->assertEquals('enqueue:setup-broker', $attributeInstance->name, 'The command name is not set correctly in the AsCommand attribute.'); } public function testShouldHaveCommandAliases() diff --git a/pkg/enqueue/Tests/Symfony/Client/SimpleConsumeCommandTest.php b/pkg/enqueue/Tests/Symfony/Client/SimpleConsumeCommandTest.php index fb89dae32..60d409325 100644 --- a/pkg/enqueue/Tests/Symfony/Client/SimpleConsumeCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Client/SimpleConsumeCommandTest.php @@ -34,13 +34,6 @@ public function testCouldBeConstructedWithRequiredAttributes() new SimpleConsumeCommand($this->createQueueConsumerMock(), $this->createDriverStub(), $this->createDelegateProcessorMock()); } - public function testShouldHaveCommandName() - { - $command = new SimpleConsumeCommand($this->createQueueConsumerMock(), $this->createDriverStub(), $this->createDelegateProcessorMock()); - - $this->assertEquals('enqueue:consume', $command->getName()); - } - public function testShouldHaveExpectedOptions() { $command = new SimpleConsumeCommand($this->createQueueConsumerMock(), $this->createDriverStub(), $this->createDelegateProcessorMock()); diff --git a/pkg/enqueue/Tests/Symfony/Client/SimpleProduceCommandTest.php b/pkg/enqueue/Tests/Symfony/Client/SimpleProduceCommandTest.php index 71ac20f38..2775870b6 100644 --- a/pkg/enqueue/Tests/Symfony/Client/SimpleProduceCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Client/SimpleProduceCommandTest.php @@ -28,13 +28,6 @@ public function testCouldBeConstructedWithContainerAsFirstArgument() new SimpleProduceCommand($this->createProducerMock()); } - public function testShouldHaveCommandName() - { - $command = new SimpleProduceCommand($this->createProducerMock()); - - $this->assertEquals('enqueue:produce', $command->getName()); - } - public function testShouldHaveExpectedOptions() { $command = new SimpleProduceCommand($this->createProducerMock()); diff --git a/pkg/enqueue/Tests/Symfony/Client/SimpleRoutesCommandTest.php b/pkg/enqueue/Tests/Symfony/Client/SimpleRoutesCommandTest.php index 469334b02..356f3f9f4 100644 --- a/pkg/enqueue/Tests/Symfony/Client/SimpleRoutesCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Client/SimpleRoutesCommandTest.php @@ -30,13 +30,6 @@ public function testCouldBeConstructedWithConfigAndRouteCollectionAsArguments() new SimpleRoutesCommand($this->createDriverMock()); } - public function testShouldHaveCommandName() - { - $command = new SimpleRoutesCommand($this->createDriverMock()); - - $this->assertEquals('enqueue:routes', $command->getName()); - } - public function testShouldHaveCommandAliases() { $command = new SimpleRoutesCommand($this->createDriverMock()); diff --git a/pkg/enqueue/Tests/Symfony/Client/SimpleSetupBrokerCommandTest.php b/pkg/enqueue/Tests/Symfony/Client/SimpleSetupBrokerCommandTest.php index f9a66129c..91802ff11 100644 --- a/pkg/enqueue/Tests/Symfony/Client/SimpleSetupBrokerCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Client/SimpleSetupBrokerCommandTest.php @@ -28,13 +28,6 @@ public function testCouldBeConstructedWithContainerAsFirstArgument() new SimpleSetupBrokerCommand($this->createClientDriverMock()); } - public function testShouldHaveCommandName() - { - $command = new SimpleSetupBrokerCommand($this->createClientDriverMock()); - - $this->assertEquals('enqueue:setup-broker', $command->getName()); - } - public function testShouldHaveCommandAliases() { $command = new SimpleSetupBrokerCommand($this->createClientDriverMock()); diff --git a/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php b/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php index c788d5e75..84d6dff84 100644 --- a/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php @@ -15,6 +15,7 @@ use Interop\Queue\Queue as InteropQueue; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; @@ -37,11 +38,22 @@ public function testCouldBeConstructedWithRequiredAttributes() new ConfigurableConsumeCommand($this->createMock(ContainerInterface::class), 'default'); } - public function testShouldHaveCommandName() + public function testShouldHaveAsCommandAttributeWithCommandName() { - $command = new ConfigurableConsumeCommand($this->createMock(ContainerInterface::class), 'default'); + $commandClass = ConfigurableConsumeCommand::class; + + $reflectionClass = new \ReflectionClass($commandClass); + + $attributes = $reflectionClass->getAttributes(AsCommand::class); + + $this->assertNotEmpty($attributes, 'The command does not have the AsCommand attribute.'); + + // Get the first attribute instance (assuming there is only one AsCommand attribute) + $asCommandAttribute = $attributes[0]; - $this->assertEquals('enqueue:transport:consume', $command->getName()); + // Verify the 'name' parameter value + $attributeInstance = $asCommandAttribute->newInstance(); + $this->assertEquals('enqueue:transport:consume', $attributeInstance->name, 'The command name is not set correctly in the AsCommand attribute.'); } public function testShouldHaveExpectedOptions() @@ -192,7 +204,7 @@ public function testShouldExecuteConsumptionWithSeveralCustomQueues() public function testShouldExecuteConsumptionWhenProcessorImplementsQueueSubscriberInterface() { - $processor = new class() implements Processor, QueueSubscriberInterface { + $processor = new class implements Processor, QueueSubscriberInterface { public function process(InteropMessage $message, Context $context) { } diff --git a/pkg/enqueue/Tests/Symfony/Consumption/ConsumeCommandTest.php b/pkg/enqueue/Tests/Symfony/Consumption/ConsumeCommandTest.php index 348397137..3c16cde3d 100644 --- a/pkg/enqueue/Tests/Symfony/Consumption/ConsumeCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Consumption/ConsumeCommandTest.php @@ -17,6 +17,7 @@ use Interop\Queue\Queue; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; @@ -39,11 +40,22 @@ public function testCouldBeConstructedWithRequiredAttributes() new ConsumeCommand($this->createMock(ContainerInterface::class), 'default'); } - public function testShouldHaveCommandName() + public function testShouldHaveAsCommandAttributeWithCommandName() { - $command = new ConsumeCommand($this->createMock(ContainerInterface::class), 'default'); + $commandClass = ConsumeCommand::class; + + $reflectionClass = new \ReflectionClass($commandClass); + + $attributes = $reflectionClass->getAttributes(AsCommand::class); + + $this->assertNotEmpty($attributes, 'The command does not have the AsCommand attribute.'); + + // Get the first attribute instance (assuming there is only one AsCommand attribute) + $asCommandAttribute = $attributes[0]; - $this->assertEquals('enqueue:transport:consume', $command->getName()); + // Verify the 'name' parameter value + $attributeInstance = $asCommandAttribute->newInstance(); + $this->assertEquals('enqueue:transport:consume', $attributeInstance->name, 'The command name is not set correctly in the AsCommand attribute.'); } public function testShouldHaveExpectedOptions() @@ -185,7 +197,7 @@ private function createContextWithoutSubscriptionConsumerMock(): InteropContext /** * @return \PHPUnit\Framework\MockObject\MockObject|InteropContext */ - private function createContextStub(Consumer $consumer = null): InteropContext + private function createContextStub(?Consumer $consumer = null): InteropContext { $context = $this->createContextWithoutSubscriptionConsumerMock(); $context diff --git a/pkg/enqueue/Tests/Symfony/Consumption/SimpleConsumeCommandTest.php b/pkg/enqueue/Tests/Symfony/Consumption/SimpleConsumeCommandTest.php index 19b9d76f8..d54a70e58 100644 --- a/pkg/enqueue/Tests/Symfony/Consumption/SimpleConsumeCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Consumption/SimpleConsumeCommandTest.php @@ -29,13 +29,6 @@ public function testCouldBeConstructedWithRequiredAttributes() new SimpleConsumeCommand($this->createQueueConsumerMock()); } - public function testShouldHaveCommandName() - { - $command = new SimpleConsumeCommand($this->createQueueConsumerMock()); - - $this->assertEquals('enqueue:transport:consume', $command->getName()); - } - public function testShouldHaveExpectedOptions() { $command = new SimpleConsumeCommand($this->createQueueConsumerMock()); From 4c1b0cddbd62a75832304123b679217f8f952261 Mon Sep 17 00:00:00 2001 From: Viktor Zavitkov Date: Thu, 14 Nov 2024 15:24:42 +0300 Subject: [PATCH 4/9] fix code style --- pkg/enqueue/Symfony/Client/ConsumeCommand.php | 4 ++-- pkg/enqueue/Symfony/Client/ProduceCommand.php | 2 +- pkg/enqueue/Symfony/Client/RoutesCommand.php | 2 +- pkg/enqueue/Symfony/Client/SetupBrokerCommand.php | 2 +- .../Symfony/Consumption/ConfigurableConsumeCommand.php | 4 ++-- pkg/enqueue/Symfony/Consumption/ConsumeCommand.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/enqueue/Symfony/Client/ConsumeCommand.php b/pkg/enqueue/Symfony/Client/ConsumeCommand.php index c97dd3a33..5a0676705 100644 --- a/pkg/enqueue/Symfony/Client/ConsumeCommand.php +++ b/pkg/enqueue/Symfony/Client/ConsumeCommand.php @@ -58,7 +58,7 @@ public function __construct( string $defaultClient, string $queueConsumerIdPattern = 'enqueue.client.%s.queue_consumer', string $driverIdPattern = 'enqueue.client.%s.driver', - string $processorIdPatter = 'enqueue.client.%s.delegate_processor' + string $processorIdPatter = 'enqueue.client.%s.delegate_processor', ) { $this->container = $container; $this->defaultClient = $defaultClient; @@ -66,7 +66,7 @@ public function __construct( $this->driverIdPattern = $driverIdPattern; $this->processorIdPattern = $processorIdPatter; - parent::__construct(self::$defaultName); + parent::__construct(); } protected function configure(): void diff --git a/pkg/enqueue/Symfony/Client/ProduceCommand.php b/pkg/enqueue/Symfony/Client/ProduceCommand.php index 512dd5f25..bd23c16c3 100644 --- a/pkg/enqueue/Symfony/Client/ProduceCommand.php +++ b/pkg/enqueue/Symfony/Client/ProduceCommand.php @@ -37,7 +37,7 @@ public function __construct(ContainerInterface $container, string $defaultClient $this->defaultClient = $defaultClient; $this->producerIdPattern = $producerIdPattern; - parent::__construct(static::$defaultName); + parent::__construct(); } protected function configure(): void diff --git a/pkg/enqueue/Symfony/Client/RoutesCommand.php b/pkg/enqueue/Symfony/Client/RoutesCommand.php index 99979d5c1..0646e37bb 100644 --- a/pkg/enqueue/Symfony/Client/RoutesCommand.php +++ b/pkg/enqueue/Symfony/Client/RoutesCommand.php @@ -43,7 +43,7 @@ public function __construct(ContainerInterface $container, string $defaultClient $this->defaultClient = $defaultClient; $this->driverIdPatter = $driverIdPatter; - parent::__construct(static::$defaultName); + parent::__construct(); } protected function configure(): void diff --git a/pkg/enqueue/Symfony/Client/SetupBrokerCommand.php b/pkg/enqueue/Symfony/Client/SetupBrokerCommand.php index 78bb4041d..b74902aa6 100644 --- a/pkg/enqueue/Symfony/Client/SetupBrokerCommand.php +++ b/pkg/enqueue/Symfony/Client/SetupBrokerCommand.php @@ -36,7 +36,7 @@ public function __construct(ContainerInterface $container, string $defaultClient $this->defaultClient = $defaultClient; $this->driverIdPattern = $driverIdPattern; - parent::__construct(static::$defaultName); + parent::__construct(); } protected function configure(): void diff --git a/pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php b/pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php index 2847ca569..230a0dc69 100644 --- a/pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php +++ b/pkg/enqueue/Symfony/Consumption/ConfigurableConsumeCommand.php @@ -46,14 +46,14 @@ public function __construct( ContainerInterface $container, string $defaultTransport, string $queueConsumerIdPattern = 'enqueue.transport.%s.queue_consumer', - string $processorRegistryIdPattern = 'enqueue.transport.%s.processor_registry' + string $processorRegistryIdPattern = 'enqueue.transport.%s.processor_registry', ) { $this->container = $container; $this->defaultTransport = $defaultTransport; $this->queueConsumerIdPattern = $queueConsumerIdPattern; $this->processorRegistryIdPattern = $processorRegistryIdPattern; - parent::__construct(static::$defaultName); + parent::__construct(); } protected function configure(): void diff --git a/pkg/enqueue/Symfony/Consumption/ConsumeCommand.php b/pkg/enqueue/Symfony/Consumption/ConsumeCommand.php index c8de790b8..1c82f3cfb 100644 --- a/pkg/enqueue/Symfony/Consumption/ConsumeCommand.php +++ b/pkg/enqueue/Symfony/Consumption/ConsumeCommand.php @@ -41,7 +41,7 @@ public function __construct(ContainerInterface $container, string $defaultTransp $this->defaultTransport = $defaultTransport; $this->queueConsumerIdPattern = $queueConsumerIdPattern; - parent::__construct(static::$defaultName); + parent::__construct(); } protected function configure(): void From 922b26c8f0e77df031c477c7edc53f28026c167f Mon Sep 17 00:00:00 2001 From: Viktor Zavitkov Date: Fri, 15 Nov 2024 00:58:58 +0300 Subject: [PATCH 5/9] fix sf 7 dependencies --- .github/workflows/ci.yml | 6 ++++++ composer.json | 3 ++- pkg/enqueue-bundle/composer.json | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21cc407be..1f3b500e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,6 +80,9 @@ jobs: php: ['8.1', '8.2'] symfony_version: ['6.2.*', '6.3.*', '6.4.*', '7.0.*'] dependencies: ['--prefer-lowest', '--prefer-dist'] + exclude: + - php: '8.1' + symfony_version: '7.0.*' name: PHP ${{ matrix.php }} unit tests on Sf ${{ matrix.symfony_version }}, deps=${{ matrix.dependencies }} @@ -121,6 +124,9 @@ jobs: php: [ '8.1', '8.2' ] symfony_version: [ '6.2.*', '6.3.*', '6.4.*', '7.0.*' ] dependencies: [ '--prefer-lowest', '--prefer-dist' ] + exclude: + - php: '8.1' + symfony_version: '7.0.*' name: PHP ${{ matrix.php }} functional tests on Sf ${{ matrix.symfony_version }}, deps=${{ matrix.dependencies }} diff --git a/composer.json b/composer.json index e17ab6570..c1abd1b87 100644 --- a/composer.json +++ b/composer.json @@ -67,7 +67,7 @@ "symfony/yaml": "^5.4|^6.0", "empi89/php-amqp-stubs": "*@dev", "doctrine/doctrine-bundle": "^2.3.2", - "doctrine/mongodb-odm-bundle": "^3.5|^4.3", + "doctrine/mongodb-odm-bundle": "^3.5|^4.3|^5.0", "alcaeus/mongo-php-adapter": "^1.0", "kwn/php-rdkafka-stubs": "^2.0.3", "friendsofphp/php-cs-fixer": "^3.4", @@ -137,3 +137,4 @@ } } } + diff --git a/pkg/enqueue-bundle/composer.json b/pkg/enqueue-bundle/composer.json index 1a070ee50..99d237bf6 100644 --- a/pkg/enqueue-bundle/composer.json +++ b/pkg/enqueue-bundle/composer.json @@ -37,7 +37,7 @@ "enqueue/async-command": "0.10.x-dev", "php-amqplib/php-amqplib": "^3.0", "doctrine/doctrine-bundle": "^2.3.2", - "doctrine/mongodb-odm-bundle": "^3.5|^4.3", + "doctrine/mongodb-odm-bundle": "^3.5|^4.3|^5.0", "alcaeus/mongo-php-adapter": "^1.0", "symfony/browser-kit": "^6.2|^7.0", "symfony/expression-language": "^6.2|^7.0", From 5d3d1973042f0c9df15e4b4bef057a99c89c7727 Mon Sep 17 00:00:00 2001 From: Viktor Zavitkov Date: Fri, 15 Nov 2024 10:44:13 +0300 Subject: [PATCH 6/9] fix tests --- .../Tests/Functional/App/CustomAppKernel.php | 2 +- .../Tests/Functional/LazyProducerTest.php | 12 ------------ pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php | 6 ------ 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php b/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php index 11fa323d7..88618d5c3 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php +++ b/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php @@ -27,7 +27,7 @@ class CustomAppKernel extends Kernel ], ]; - public function setEnqueueConfig(array $config) + public function setEnqueueConfig(array $config): void { $this->enqueueConfig = array_replace_recursive($this->enqueueConfig, $config); $this->enqueueConfig['default']['client']['app_name'] = str_replace('.', '', uniqid('app_name', true)); diff --git a/pkg/enqueue-bundle/Tests/Functional/LazyProducerTest.php b/pkg/enqueue-bundle/Tests/Functional/LazyProducerTest.php index 858b80a1c..18375aef3 100644 --- a/pkg/enqueue-bundle/Tests/Functional/LazyProducerTest.php +++ b/pkg/enqueue-bundle/Tests/Functional/LazyProducerTest.php @@ -4,7 +4,6 @@ use Enqueue\Bundle\Tests\Functional\App\CustomAppKernel; use Enqueue\Symfony\Client\LazyProducer; -use Symfony\Component\Filesystem\Filesystem; /** * @group functional @@ -17,17 +16,6 @@ protected function setUp(): void // parent::setUp(); } - protected function tearDown(): void - { - if (static::$kernel) { - $fs = new Filesystem(); - $fs->remove(static::$kernel->getLogDir()); - $fs->remove(static::$kernel->getCacheDir()); - } - - parent::tearDown(); - } - public function testShouldAllowGetLazyProducerWithoutError() { $this->customSetUp([ diff --git a/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php b/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php index ad278d599..56bec7cb2 100644 --- a/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php +++ b/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php @@ -32,12 +32,6 @@ protected function tearDown(): void $this->getContext()->close(); } - if (static::$kernel) { - $fs = new Filesystem(); - $fs->remove(static::$kernel->getLogDir()); - $fs->remove(static::$kernel->getCacheDir()); - } - parent::tearDown(); } From d209c4a563074fbf44ad42cc94a3dae44b4b718a Mon Sep 17 00:00:00 2001 From: Viktor Zavitkov Date: Fri, 15 Nov 2024 11:35:41 +0300 Subject: [PATCH 7/9] fix phpstan --- .github/workflows/ci.yml | 4 ++-- .../Symfony/Consumption/ConfigurableConsumeCommandTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f3b500e8..7de6af7d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: extensions: mongodb, redis, :xdebug ini-values: memory_limit=2048M - - run: php ./bin/fix-symfony-version.php "5.4.*" + - run: php ./bin/fix-symfony-version.php "6.2.*" - uses: "ramsey/composer-install@v1" @@ -63,7 +63,7 @@ jobs: extensions: mongodb, redis, :xdebug ini-values: memory_limit=2048M - - run: php ./bin/fix-symfony-version.php "5.4.*" + - run: php ./bin/fix-symfony-version.php "6.2.*" - run: composer update --no-progress diff --git a/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php b/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php index 84d6dff84..e697b4a31 100644 --- a/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php @@ -204,7 +204,7 @@ public function testShouldExecuteConsumptionWithSeveralCustomQueues() public function testShouldExecuteConsumptionWhenProcessorImplementsQueueSubscriberInterface() { - $processor = new class implements Processor, QueueSubscriberInterface { + $processor = new class() implements Processor, QueueSubscriberInterface { public function process(InteropMessage $message, Context $context) { } From a8d2c4b8645d6125111e33c194adad4e6bfe8b56 Mon Sep 17 00:00:00 2001 From: Viktor Zavitkov Date: Fri, 15 Nov 2024 15:23:39 +0300 Subject: [PATCH 8/9] fix code style and php8.2 sf7 dependencies --- .github/workflows/ci.yml | 4 ++-- composer.json | 1 - .../Tests/Functional/App/CustomAppKernel.php | 10 ++-------- .../Tests/Functional/UseCasesTest.php | 13 ++++++------- .../Consumption/ConfigurableConsumeCommandTest.php | 4 ++-- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7de6af7d6..1f3b500e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: extensions: mongodb, redis, :xdebug ini-values: memory_limit=2048M - - run: php ./bin/fix-symfony-version.php "6.2.*" + - run: php ./bin/fix-symfony-version.php "5.4.*" - uses: "ramsey/composer-install@v1" @@ -63,7 +63,7 @@ jobs: extensions: mongodb, redis, :xdebug ini-values: memory_limit=2048M - - run: php ./bin/fix-symfony-version.php "6.2.*" + - run: php ./bin/fix-symfony-version.php "5.4.*" - run: composer update --no-progress diff --git a/composer.json b/composer.json index c1abd1b87..29266f343 100644 --- a/composer.json +++ b/composer.json @@ -125,7 +125,6 @@ "ext-amqp": "1.9.3", "ext-gearman": "2.0.3", "ext-rdkafka": "4.0", - "ext-mongodb": "1.5", "ext-bcmath": "1", "ext-mbstring": "1", "ext-mongo": "1.6.14", diff --git a/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php b/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php index 88618d5c3..81d73796e 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php +++ b/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php @@ -7,7 +7,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpKernel\Kernel; -use Symfony\Component\Routing\RouteCollectionBuilder; +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; class CustomAppKernel extends Kernel { @@ -64,9 +64,6 @@ protected function getContainerClass(): string return parent::getContainerClass().'Custom'.$this->enqueueConfigId; } - /** - * {@inheritdoc} - */ protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) { if (self::VERSION_ID < 60000) { @@ -78,10 +75,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load $c->loadFromExtension('enqueue', $this->enqueueConfig); } - /** - * {@inheritdoc} - */ - protected function configureRoutes(RouteCollectionBuilder $routes) + protected function configureRoutes(RoutingConfigurator $routes) { } } diff --git a/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php b/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php index 56bec7cb2..7417412bd 100644 --- a/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php +++ b/pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php @@ -11,7 +11,6 @@ use Interop\Queue\Message; use Interop\Queue\Queue; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\Filesystem\Filesystem; /** * @group functional @@ -147,12 +146,12 @@ public function provideEnqueueConfigs() ], ]]; -// -// yield 'gps' => [[ -// 'transport' => [ -// 'dsn' => getenv('GPS_DSN'), -// ], -// ]]; + // + // yield 'gps' => [[ + // 'transport' => [ + // 'dsn' => getenv('GPS_DSN'), + // ], + // ]]; } /** diff --git a/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php b/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php index e697b4a31..c448c1cf5 100644 --- a/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php +++ b/pkg/enqueue/Tests/Symfony/Consumption/ConfigurableConsumeCommandTest.php @@ -204,8 +204,8 @@ public function testShouldExecuteConsumptionWithSeveralCustomQueues() public function testShouldExecuteConsumptionWhenProcessorImplementsQueueSubscriberInterface() { - $processor = new class() implements Processor, QueueSubscriberInterface { - public function process(InteropMessage $message, Context $context) + $processor = new class implements Processor, QueueSubscriberInterface { + public function process(InteropMessage $message, Context $context): void { } From 9570303195549a9201c34ddd6ce503b61092aa0b Mon Sep 17 00:00:00 2001 From: Viktor Zavitkov Date: Fri, 15 Nov 2024 20:59:32 +0300 Subject: [PATCH 9/9] another tests fixed --- composer.json | 26 +++--- .../ContainerAwareRegistry.php | 29 +++---- .../DependencyInjection/Configuration.php | 5 +- .../Resources/config/services.yml | 4 +- .../Tests/ContainerAwareRegistryTest.php | 38 ++++----- pkg/job-queue/Tests/Functional/Entity/Job.php | 84 ++++--------------- .../Tests/Functional/Entity/JobUnique.php | 12 +-- .../Tests/Functional/app/AppKernel.php | 6 +- .../Tests/Functional/app/config/config.yml | 2 +- 9 files changed, 64 insertions(+), 142 deletions(-) diff --git a/composer.json b/composer.json index 29266f343..5308d33dd 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "phpstan": "bin/phpstan analyse --memory-limit=512M -c phpstan.neon" }, "require": { - "php": "^7.4|^8.0", + "php": "^8.1", "ext-amqp": "^1.9.3|^2.0.0", "ext-gearman": "^2.0", @@ -53,18 +53,18 @@ "phpunit/phpunit": "^9.5", "phpstan/phpstan": "^0.12", "queue-interop/queue-spec": "^0.6.2", - "symfony/browser-kit": "^5.4|^6.0", - "symfony/config": "^5.4|^6.0", - "symfony/process": "^5.4|^6.0", - "symfony/console": "^5.4|^6.0", - "symfony/dependency-injection": "^5.4|^6.0", - "symfony/event-dispatcher": "^5.4|^6.0", - "symfony/expression-language": "^5.4|^6.0", - "symfony/http-kernel": "^5.4|^6.0", - "symfony/filesystem": "^5.4|^6.0", - "symfony/framework-bundle": "^5.4|^6.0", - "symfony/validator": "^5.4|^6.0", - "symfony/yaml": "^5.4|^6.0", + "symfony/browser-kit": "^6.2|^7.0", + "symfony/config": "^6.2|^7.0", + "symfony/process": "^6.2|^7.0", + "symfony/console": "^6.2|^7.0", + "symfony/dependency-injection": "^6.2|^7.0", + "symfony/event-dispatcher": "^6.2|^7.0", + "symfony/expression-language": "^6.2|^7.0", + "symfony/http-kernel": "^^6.2|^7.0", + "symfony/filesystem": "^6.2|^7.0", + "symfony/framework-bundle": "^^6.2|^7.0", + "symfony/validator": "^6.2|^7.0", + "symfony/yaml": "^6.2|^7.0", "empi89/php-amqp-stubs": "*@dev", "doctrine/doctrine-bundle": "^2.3.2", "doctrine/mongodb-odm-bundle": "^3.5|^4.3|^5.0", diff --git a/pkg/async-event-dispatcher/ContainerAwareRegistry.php b/pkg/async-event-dispatcher/ContainerAwareRegistry.php index 2763ed72b..b0e23f222 100644 --- a/pkg/async-event-dispatcher/ContainerAwareRegistry.php +++ b/pkg/async-event-dispatcher/ContainerAwareRegistry.php @@ -2,12 +2,14 @@ namespace Enqueue\AsyncEventDispatcher; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerAwareTrait; +use Psr\Container\ContainerInterface; -class ContainerAwareRegistry implements Registry, ContainerAwareInterface +class ContainerAwareRegistry implements Registry { - use ContainerAwareTrait; + /** + * @var ContainerInterface + */ + private $container; /** * @var string[] @@ -23,15 +25,13 @@ class ContainerAwareRegistry implements Registry, ContainerAwareInterface * @param string[] $eventsMap [eventName => transformerName] * @param string[] $transformersMap [transformerName => transformerServiceId] */ - public function __construct(array $eventsMap, array $transformersMap) + public function __construct(array $eventsMap, array $transformersMap, ContainerInterface $container) { $this->eventsMap = $eventsMap; $this->transformersMap = $transformersMap; + $this->container = $container; } - /** - * {@inheritdoc} - */ public function getTransformerNameForEvent($eventName) { $transformerName = null; @@ -39,7 +39,7 @@ public function getTransformerNameForEvent($eventName) $transformerName = $this->eventsMap[$eventName]; } else { foreach ($this->eventsMap as $eventNamePattern => $name) { - if ('/' != $eventNamePattern[0]) { + if ('/' !== $eventNamePattern[0]) { continue; } @@ -58,9 +58,6 @@ public function getTransformerNameForEvent($eventName) return $transformerName; } - /** - * {@inheritdoc} - */ public function getTransformer($name) { if (false == array_key_exists($name, $this->transformersMap)) { @@ -69,12 +66,8 @@ public function getTransformer($name) $transformer = $this->container->get($this->transformersMap[$name]); - if (false == $transformer instanceof EventTransformer) { - throw new \LogicException(sprintf( - 'The container must return instance of %s but got %s', - EventTransformer::class, - is_object($transformer) ? get_class($transformer) : gettype($transformer) - )); + if (false == $transformer instanceof EventTransformer) { + throw new \LogicException(sprintf('The container must return instance of %s but got %s', EventTransformer::class, is_object($transformer) ? $transformer::class : gettype($transformer))); } return $transformer; diff --git a/pkg/async-event-dispatcher/DependencyInjection/Configuration.php b/pkg/async-event-dispatcher/DependencyInjection/Configuration.php index 56151e956..7b85a469d 100644 --- a/pkg/async-event-dispatcher/DependencyInjection/Configuration.php +++ b/pkg/async-event-dispatcher/DependencyInjection/Configuration.php @@ -7,10 +7,7 @@ class Configuration implements ConfigurationInterface { - /** - * {@inheritdoc} - */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { if (method_exists(TreeBuilder::class, 'getRootNode')) { $tb = new TreeBuilder('enqueue_async_event_dispatcher'); diff --git a/pkg/async-event-dispatcher/Resources/config/services.yml b/pkg/async-event-dispatcher/Resources/config/services.yml index 2b3fbc0b0..67365dcb5 100644 --- a/pkg/async-event-dispatcher/Resources/config/services.yml +++ b/pkg/async-event-dispatcher/Resources/config/services.yml @@ -8,9 +8,7 @@ services: enqueue.events.registry: class: 'Enqueue\AsyncEventDispatcher\ContainerAwareRegistry' public: false - arguments: [[], []] - calls: - - ['setContainer', ['@service_container']] + arguments: [[], [], '@service_container'] enqueue.events.async_listener: class: 'Enqueue\AsyncEventDispatcher\AsyncListener' diff --git a/pkg/async-event-dispatcher/Tests/ContainerAwareRegistryTest.php b/pkg/async-event-dispatcher/Tests/ContainerAwareRegistryTest.php index 3be3b5f3c..79762ac17 100644 --- a/pkg/async-event-dispatcher/Tests/ContainerAwareRegistryTest.php +++ b/pkg/async-event-dispatcher/Tests/ContainerAwareRegistryTest.php @@ -20,37 +20,25 @@ public function testShouldImplementRegistryInterface() $this->assertClassImplements(Registry::class, ContainerAwareRegistry::class); } - public function testCouldBeConstructedWithEventsMapAndTransformersMapAsArguments() - { - new ContainerAwareRegistry([], []); - } - - public function testShouldSetContainerToContainerProperty() + public function testShouldAllowGetTransportNameByEventName() { $container = new Container(); - $registry = new ContainerAwareRegistry([], []); - - $registry->setContainer($container); - - $this->assertAttributeSame($container, 'container', $registry); - } - - public function testShouldAllowGetTransportNameByEventName() - { $registry = new ContainerAwareRegistry([ - 'fooEvent' => 'fooTrans', - ], []); + 'fooEvent' => 'fooTrans', + ], [], $container); $this->assertEquals('fooTrans', $registry->getTransformerNameForEvent('fooEvent')); } public function testShouldAllowDefineTransportNameAsRegExpPattern() { + $container = new Container(); + $registry = new ContainerAwareRegistry([ '/.*/' => 'fooRegExpTrans', 'fooEvent' => 'fooTrans', - ], []); + ], [], $container); // guard $this->assertEquals('fooTrans', $registry->getTransformerNameForEvent('fooEvent')); @@ -60,9 +48,11 @@ public function testShouldAllowDefineTransportNameAsRegExpPattern() public function testThrowIfNotSupportedEventGiven() { + $container = new Container(); + $registry = new ContainerAwareRegistry([ 'fooEvent' => 'fooTrans', - ], []); + ], [], $container); $this->expectException(\LogicException::class); $this->expectExceptionMessage('There is no transformer registered for the given event fooNotSupportedEvent'); @@ -71,9 +61,11 @@ public function testThrowIfNotSupportedEventGiven() public function testThrowIfThereIsNoRegisteredTransformerWithSuchName() { + $container = new Container(); + $registry = new ContainerAwareRegistry([], [ 'fooTrans' => 'foo_trans_id', - ]); + ], $container); $this->expectException(\LogicException::class); $this->expectExceptionMessage('There is no transformer named fooNotRegisteredName'); @@ -87,8 +79,7 @@ public function testThrowIfContainerReturnsServiceNotInstanceOfEventTransformer( $registry = new ContainerAwareRegistry([], [ 'fooTrans' => 'foo_trans_id', - ]); - $registry->setContainer($container); + ], $container); $this->expectException(\LogicException::class); $this->expectExceptionMessage('The container must return instance of Enqueue\AsyncEventDispatcher\EventTransformer but got stdClass'); @@ -104,8 +95,7 @@ public function testShouldReturnEventTransformer() $registry = new ContainerAwareRegistry([], [ 'fooTrans' => 'foo_trans_id', - ]); - $registry->setContainer($container); + ], $container); $this->assertSame($eventTransformerMock, $registry->getTransformer('fooTrans')); } diff --git a/pkg/job-queue/Tests/Functional/Entity/Job.php b/pkg/job-queue/Tests/Functional/Entity/Job.php index ccbf4fda9..ad90e58a0 100644 --- a/pkg/job-queue/Tests/Functional/Entity/Job.php +++ b/pkg/job-queue/Tests/Functional/Entity/Job.php @@ -6,97 +6,47 @@ use Doctrine\ORM\Mapping as ORM; use Enqueue\JobQueue\Job as BaseJob; -/** - * @ORM\Entity - * @ORM\Table(name="enqueue_job_queue") - */ +#[ORM\Entity] +#[ORM\Table(name: 'enqueue_job_queue')] class Job extends BaseJob { - /** - * @var int - * - * @ORM\Column(name="id", type="integer") - * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") - */ + #[ORM\Column(name: 'id', type: 'integer')] + #[ORM\Id] + #[ORM\GeneratedValue(strategy: 'AUTO')] protected $id; - /** - * @var string - * - * @ORM\Column(name="owner_id", type="string", nullable=true) - */ + #[ORM\Column(name: 'owner_id', type: 'string', nullable: true)] protected $ownerId; - /** - * @var string - * - * @ORM\Column(name="name", type="string", nullable=false) - */ + #[ORM\Column(name: 'name', type: 'string', nullable: false)] protected $name; - /** - * @var string - * - * @ORM\Column(name="status", type="string", nullable=false) - */ + #[ORM\Column(name: 'status', type: 'string', nullable: false)] protected $status; - /** - * @var bool - * - * @ORM\Column(name="interrupted", type="boolean") - */ + #[ORM\Column(name: 'interrupted', type: 'boolean')] protected $interrupted; - /** - * @var bool; - * - * @ORM\Column(name="`unique`", type="boolean") - */ + #[ORM\Column(name: '`unique`', type: 'boolean')] protected $unique; - /** - * @var Job - * - * @ORM\ManyToOne(targetEntity="Job", inversedBy="childJobs") - * @ORM\JoinColumn(name="root_job_id", referencedColumnName="id", onDelete="CASCADE") - */ + #[ORM\ManyToOne(targetEntity: 'Job', inversedBy: 'childJobs')] + #[ORM\JoinColumn(name: 'root_job_id', referencedColumnName: 'id', onDelete: 'CASCADE')] protected $rootJob; - /** - * @var Job[] - * - * @ORM\OneToMany(targetEntity="Job", mappedBy="rootJob") - */ + #[ORM\OneToMany(mappedBy: 'rootJob', targetEntity: 'Job')] protected $childJobs; - /** - * @var \DateTime - * - * @ORM\Column(name="created_at", type="datetime", nullable=false) - */ + #[ORM\Column(name: 'created_at', type: 'datetime', nullable: false)] protected $createdAt; - /** - * @var \DateTime - * - * @ORM\Column(name="started_at", type="datetime", nullable=true) - */ + #[ORM\Column(name: 'started_at', type: 'datetime', nullable: true)] protected $startedAt; - /** - * @var \DateTime - * - * @ORM\Column(name="stopped_at", type="datetime", nullable=true) - */ + #[ORM\Column(name: 'stopped_at', type: 'datetime', nullable: true)] protected $stoppedAt; - /** - * @var array - * - * @ORM\Column(name="data", type="json", nullable=true) - */ + #[ORM\Column(name: 'data', type: 'json', nullable: true)] protected $data; public function __construct() diff --git a/pkg/job-queue/Tests/Functional/Entity/JobUnique.php b/pkg/job-queue/Tests/Functional/Entity/JobUnique.php index 4d8a33745..6d10ea2a5 100644 --- a/pkg/job-queue/Tests/Functional/Entity/JobUnique.php +++ b/pkg/job-queue/Tests/Functional/Entity/JobUnique.php @@ -4,15 +4,11 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="enqueue_job_queue_unique") - */ +#[ORM\Entity] +#[ORM\Table(name: 'enqueue_job_queue_unique')] class JobUnique { - /** - * @ORM\Id - * @ORM\Column(name="name", type="string", nullable=false) - */ + #[ORM\Id] + #[ORM\Column(name: 'name', type: 'string', nullable: false)] protected $name; } diff --git a/pkg/job-queue/Tests/Functional/app/AppKernel.php b/pkg/job-queue/Tests/Functional/app/AppKernel.php index 3cef602c2..b51969f68 100644 --- a/pkg/job-queue/Tests/Functional/app/AppKernel.php +++ b/pkg/job-queue/Tests/Functional/app/AppKernel.php @@ -1,7 +1,5 @@