diff --git a/composer.json b/composer.json index 66d8feb..60221cb 100644 --- a/composer.json +++ b/composer.json @@ -10,14 +10,14 @@ } ], "require": { - "php": ">=7.4", + "php": ">=8.1.0", "ext-rdkafka": "*", "ext-json": "*", - "symfony/config": "^4.3.3|^5.0|^6.0|^7.0", - "symfony/dependency-injection": "^4.3.3|^5.2|^6.0|^7.0", - "symfony/http-kernel": "^4.3|^5.2.1|^6.0|^7.0", - "symfony/console": "^4.0|^5.2.0|^6.0|^7.0", - "symfony/options-resolver": "~4.3|^5.2|^6.0|^7.0", + "symfony/config": "^6.4|^7.0", + "symfony/dependency-injection": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/console": "^6.4|^7.0", + "symfony/options-resolver": "^6.4|^7.0", "flix-tech/avro-serde-php": "^2.0" }, "autoload": { @@ -31,14 +31,14 @@ } }, "require-dev": { - "symfony/phpunit-bridge": "^5.2|^6.0|^7.0", - "symfony/dotenv": "5.2.*|^6.0|^7.0", + "symfony/phpunit-bridge": "^6.4|^7.0", + "symfony/dotenv": "^6.4|^7.0", "phpstan/phpstan": "^0.12.75|^1.12", "phpstan/phpstan-symfony": "^0.12.18|^1.4", "phpstan/phpstan-phpunit": "^0.12.17|^1.4", "squizlabs/php_codesniffer": "^3.5", "phpstan/extension-installer": "^1.1", - "symfony/framework-bundle": "^5.2|^6.0|^7.0", - "symfony/event-dispatcher": "^5.2|^6.0|^7.0" + "symfony/framework-bundle": "^6.4|^7.0", + "symfony/event-dispatcher": "^6.4|^7.0" } } diff --git a/src/Command/ConsumeCommand.php b/src/Command/ConsumeCommand.php index dc4a2d1..46b770e 100644 --- a/src/Command/ConsumeCommand.php +++ b/src/Command/ConsumeCommand.php @@ -11,19 +11,22 @@ use StsGamingGroup\KafkaBundle\Configuration\ConfigurationResolver; use StsGamingGroup\KafkaBundle\Configuration\RawConfiguration; use StsGamingGroup\KafkaBundle\Traits\AddConfigurationsToCommandTrait; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'kafka:consumers:consume', + description: 'Starts consuming messages from kafka using class implementing '.ConsumerInterface::class +)] class ConsumeCommand extends Command { use AddConfigurationsToCommandTrait; use DescribeTrait; - protected static $defaultName = 'kafka:consumers:consume'; - private RawConfiguration $rawConfiguration; private ConsumerProvider $consumerProvider; private ConsumerClient $consumerClient; @@ -45,14 +48,9 @@ public function __construct( protected function configure(): void { - $this->setDescription( - sprintf( - 'Starts consuming messages from kafka using class implementing %s.', - ConsumerInterface::class - ) - ) - ->addArgument('name', InputArgument::REQUIRED, 'Name of the registered consumer.') - ->addOption('describe', null, InputOption::VALUE_NONE, 'Describes consumer'); + $this + ->addArgument(name: 'name', mode: InputArgument::REQUIRED, description: 'Name of the registered consumer.') + ->addOption(name: 'describe', mode: InputOption::VALUE_NONE, description: 'Describes consumer'); $this->addConfigurations($this->rawConfiguration); } @@ -64,11 +62,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($input->getOption('describe')) { $this->describe($this->configurationResolver->resolve($consumer, $input), $output, $consumer); - return 0; + return self::SUCCESS; } $this->consumerClient->consume($consumer, $input); - return 0; + return self::SUCCESS; } } diff --git a/src/Command/ConsumersDescribeCommand.php b/src/Command/ConsumersDescribeCommand.php index 398c06a..6b42f5e 100644 --- a/src/Command/ConsumersDescribeCommand.php +++ b/src/Command/ConsumersDescribeCommand.php @@ -7,17 +7,20 @@ use StsGamingGroup\KafkaBundle\Client\Consumer\ConsumerProvider; use StsGamingGroup\KafkaBundle\Command\Traits\DescribeTrait; use StsGamingGroup\KafkaBundle\Configuration\ConfigurationResolver; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'kafka:consumers:describe', + description: 'Show consumers configuration.' +)] class ConsumersDescribeCommand extends Command { use DescribeTrait; - protected static $defaultName = 'kafka:consumers:describe'; - private ConsumerProvider $consumerProvider; private ConfigurationResolver $configurationResolver; @@ -33,9 +36,11 @@ public function __construct( protected function configure(): void { - $this - ->setDescription('Show consumers configuration.') - ->addOption('name', null, InputOption::VALUE_REQUIRED, 'Shows specific consumer configuration.'); + $this->addOption( + name: 'name', + mode: InputOption::VALUE_REQUIRED, + description: 'Shows specific consumer configuration.' + ); } protected function execute(InputInterface $input, OutputInterface $output): int @@ -47,6 +52,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->describe($this->configurationResolver->resolve($consumer), $output, $consumer); } - return 0; + return self::SUCCESS; } } diff --git a/src/Command/ProducersDescribeCommand.php b/src/Command/ProducersDescribeCommand.php index 77413d4..73efe00 100644 --- a/src/Command/ProducersDescribeCommand.php +++ b/src/Command/ProducersDescribeCommand.php @@ -7,16 +7,19 @@ use StsGamingGroup\KafkaBundle\Client\Producer\ProducerProvider; use StsGamingGroup\KafkaBundle\Command\Traits\DescribeTrait; use StsGamingGroup\KafkaBundle\Configuration\ConfigurationResolver; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand( + name: 'kafka:producers:describe', + description: 'Show producers configuration.' +)] class ProducersDescribeCommand extends Command { use DescribeTrait; - protected static $defaultName = 'kafka:producers:describe'; - private ProducerProvider $producerProvider; private ConfigurationResolver $configurationResolver; @@ -30,11 +33,6 @@ public function __construct( parent::__construct(); } - protected function configure(): void - { - $this->setDescription('Show producers configuration.'); - } - protected function execute(InputInterface $input, OutputInterface $output): int { $producers = $this->producerProvider->getProducers(); @@ -43,6 +41,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->describe($this->configurationResolver->resolve($producer), $output, $producer); } - return 0; + return self::SUCCESS; } } diff --git a/tests/Unit/Client/Consumer/ConsumerProviderTest.php b/tests/Unit/Client/Consumer/ConsumerProviderTest.php index c84c679..2835506 100644 --- a/tests/Unit/Client/Consumer/ConsumerProviderTest.php +++ b/tests/Unit/Client/Consumer/ConsumerProviderTest.php @@ -47,7 +47,7 @@ public function testMultipleConsumersFound(): void ->addConsumer($this->consumerTwo); $this->expectException(InvalidConsumerException::class); - $this->expectErrorMessageMatches('/Multiple consumers/'); + $this->expectExceptionMessageMatches('/Multiple consumers/'); $this->consumerProvider->provide('consumer_2'); } @@ -62,7 +62,7 @@ public function testNoConsumerFound(): void ->addConsumer($this->consumerTwo); $this->expectException(InvalidConsumerException::class); - $this->expectErrorMessageMatches('/no matching consumer/'); + $this->expectExceptionMessageMatches('/no matching consumer/'); $this->consumerProvider->provide('consumer_3'); } } diff --git a/tests/Unit/Configuration/ConfigurationResolverTest.php b/tests/Unit/Configuration/ConfigurationResolverTest.php index 15dbe7d..c9b85ba 100644 --- a/tests/Unit/Configuration/ConfigurationResolverTest.php +++ b/tests/Unit/Configuration/ConfigurationResolverTest.php @@ -157,7 +157,7 @@ public function testInputValueInvalid(): void $resolver = new ConfigurationResolver($rawConfiguration, $this->yamlConfig); $this->expectException(InvalidConfigurationException::class); - $this->expectDeprecationMessageMatches('/configuration_one/'); + $this->expectExceptionMessageMatches('/configuration_one/'); $resolver->resolve(DummyConsumerOne::class, $this->input); } @@ -205,7 +205,7 @@ public function testYamlConfigInvalid(): void $resolver = new ConfigurationResolver($rawConfiguration, $this->yamlConfig); $this->expectException(InvalidConfigurationException::class); - $this->expectDeprecationMessageMatches('/group_id/'); + $this->expectExceptionMessageMatches('/group_id/'); $resolver->resolve(DummyConsumerOne::class); }