diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c29d8430c..1f3b500e8 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,12 @@ 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.*' + - php: '8.1' + symfony_version: '7.0.*' name: PHP ${{ matrix.php }} unit tests on Sf ${{ matrix.symfony_version }}, deps=${{ matrix.dependencies }} @@ -127,18 +121,12 @@ 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'] + 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.*' + - 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..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,21 +53,21 @@ "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", + "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", @@ -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", @@ -137,3 +136,4 @@ } } } + 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/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php b/pkg/enqueue-bundle/Tests/Functional/App/CustomAppKernel.php index 11fa323d7..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 { @@ -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)); @@ -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/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..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 @@ -32,12 +31,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(); } @@ -153,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-bundle/composer.json b/pkg/enqueue-bundle/composer.json index 7ee50c269..99d237bf6 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", @@ -37,12 +37,12 @@ "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": "^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 + } } } 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..5a0676705 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 */ @@ -60,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; @@ -68,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 6064f82e1..bd23c16c3 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 */ @@ -39,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 59a4a4d98..0646e37bb 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 */ @@ -45,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 68aebb582..b74902aa6 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 */ @@ -38,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 234eb0497..230a0dc69 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 */ @@ -48,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 870cc5f60..1c82f3cfb 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 */ @@ -43,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 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..c448c1cf5 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,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 { } 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()); 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 @@