diff --git a/.github/workflows/rector-cs.yml b/.github/workflows/rector-cs.yml new file mode 100644 index 0000000..b0154f0 --- /dev/null +++ b/.github/workflows/rector-cs.yml @@ -0,0 +1,27 @@ +name: Rector + PHP CS Fixer + +on: + pull_request: + paths: + - 'config/**' + - 'src/**' + - 'tests/**' + - '.github/workflows/rector-cs.yml' + - 'composer.json' + - 'rector.php' + - '.php-cs-fixer.dist.php' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rector: + permissions: + contents: write # Required to commit automated Rector and CS fixes + uses: yiisoft/actions/.github/workflows/rector-cs.yml@master + with: + php: '8.1' diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml deleted file mode 100644 index ebc6d37..0000000 --- a/.github/workflows/rector.yml +++ /dev/null @@ -1,23 +0,0 @@ -on: - pull_request: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' - -name: rector - -permissions: - contents: read -jobs: - rector: - uses: yiisoft/actions/.github/workflows/rector.yml@master - with: - os: >- - ['ubuntu-latest'] - php: >- - ['8.4'] diff --git a/.gitignore b/.gitignore index 04fd490..e382898 100644 --- a/.gitignore +++ b/.gitignore @@ -33,7 +33,7 @@ phpunit.phar coverage.xml /coverage.html -# Phan -analysis.txt +# PHP CS Fixer +/.php-cs-fixer.cache tests/.env diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..2477e66 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,21 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', +]); + +return ConfigBuilder::build() + ->setRiskyAllowed(true) + ->setParallelConfig(ParallelConfigFactory::detect()) + ->setRules([ + '@Yiisoft/Core' => true, + '@Yiisoft/Core:risky' => true, + ]) + ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 1ab379b..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,85 +0,0 @@ -preset: psr12 -risky: true - -version: 8.1 - -finder: - exclude: - - docs - - vendor - -enabled: - - alpha_ordered_traits - - array_indentation - - array_push - - combine_consecutive_issets - - combine_consecutive_unsets - - combine_nested_dirname - - declare_strict_types - - dir_constant - - fully_qualified_strict_types - - function_to_constant - - hash_to_slash_comment - - is_null - - logical_operators - - magic_constant_casing - - magic_method_casing - - method_separation - - modernize_types_casting - - native_function_casing - - native_function_type_declaration_casing - - no_alias_functions - - no_empty_comment - - no_empty_phpdoc - - no_empty_statement - - no_extra_block_blank_lines - - no_short_bool_cast - - no_superfluous_elseif - - no_unneeded_control_parentheses - - no_unneeded_curly_braces - - no_unneeded_final_method - - no_unset_cast - - no_unused_imports - - no_unused_lambda_imports - - no_useless_else - - no_useless_return - - normalize_index_brace - - php_unit_dedicate_assert - - php_unit_dedicate_assert_internal_type - - php_unit_expectation - - php_unit_mock - - php_unit_mock_short_will_return - - php_unit_namespaced - - php_unit_no_expectation_annotation - - phpdoc_no_empty_return - - phpdoc_no_useless_inheritdoc - - phpdoc_order - - phpdoc_property - - phpdoc_scalar - - phpdoc_singular_inheritdoc - - phpdoc_trim - - phpdoc_trim_consecutive_blank_line_separation - - phpdoc_type_to_var - - phpdoc_types - - phpdoc_types_order - - print_to_echo - - regular_callable_call - - return_assignment - - self_accessor - - self_static_accessor - - set_type_to_cast - - short_array_syntax - - short_list_syntax - - simplified_if_return - - single_quote - - standardize_not_equals - - ternary_to_null_coalescing - - trailing_comma_in_multiline_array - - unalign_double_arrow - - unalign_equals - - empty_loop_body_braces - - integer_literal_case - - union_type_without_spaces - -disabled: - - function_declaration diff --git a/composer.json b/composer.json index 7b3216d..2990539 100644 --- a/composer.json +++ b/composer.json @@ -31,16 +31,18 @@ "yiisoft/queue": "dev-master" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.95", "infection/infection": "^0.27.8||^0.29.0", "maglnet/composer-require-checker": "^4.4", "phpbench/phpbench": "^1.4", "phpunit/phpunit": "^9.5", - "rector/rector": "^2.0.15", + "rector/rector": "^2.5.5", "roave/infection-static-analysis-plugin": "^1.16", "spatie/phpunit-watcher": "^1.23", "symfony/console": "^6.0", "symfony/process": "^6.0", "vimeo/psalm": "^5.26.1 || ^6.10.3", + "yiisoft/code-style": "^1.0", "yiisoft/test-support": "^3.0" }, "autoload": { @@ -70,5 +72,10 @@ "infection/extension-installer": true, "composer/package-versions-deprecated": true } + }, + "scripts": { + "cs-fix": "php-cs-fixer fix", + "psalm": "psalm", + "rector": "rector" } } diff --git a/rector.php b/rector.php index e68f803..54537c2 100644 --- a/rector.php +++ b/rector.php @@ -7,7 +7,6 @@ use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; -use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; return RectorConfig::configure() ->withPaths([ @@ -22,5 +21,4 @@ ClosureToArrowFunctionRector::class, ReadOnlyPropertyRector::class, NullToStrictStringFuncCallArgRector::class, - ReturnNeverTypeRector::class, ]); diff --git a/src/Adapter.php b/src/Adapter.php index 2c9b787..6427ee5 100644 --- a/src/Adapter.php +++ b/src/Adapter.php @@ -19,14 +19,15 @@ use Yiisoft\Queue\Message\Serializer\MessageSerializerInterface; use Yiisoft\Queue\MessageStatus; +use function is_string; + final class Adapter implements AdapterInterface { public function __construct( private QueueProviderInterface $queueProvider, private readonly MessageSerializerInterface $serializer, private readonly LoopInterface $loop, - ) { - } + ) {} public function withChannel(BackedEnum|string $channel): self { @@ -74,7 +75,7 @@ public function push(MessageInterface $message): MessageInterface $exchangeSettings?->getName() ?? '', $exchangeSettings ? '' : $queueProvider ->getQueueSettings() - ->getName() + ->getName(), ); return $message; @@ -117,7 +118,7 @@ function (AMQPMessage $amqpMessage) use ($handlerCallback, $channel): void { throw $exception; } - } + }, ); while ($this->loop->canContinue()) { @@ -165,7 +166,7 @@ private function getQueueProviderForMessage(MessageInterface $message): QueuePro $this->queueProvider->getQueueSettings(), $exchangeSettings, $delayMilliseconds, - ) + ), ); } @@ -198,7 +199,7 @@ private function getDelayQueueSettings( 'x-dead-letter-exchange' => ['S', $exchangeSettings->getName()], 'x-expires' => ['I', $delayMilliseconds + 30000], 'x-message-ttl' => ['I', $delayMilliseconds], - ] + ], ); } diff --git a/src/Exception/NotImplementedException.php b/src/Exception/NotImplementedException.php index 4b118f0..390fa9e 100644 --- a/src/Exception/NotImplementedException.php +++ b/src/Exception/NotImplementedException.php @@ -6,6 +6,4 @@ use RuntimeException; -final class NotImplementedException extends RuntimeException -{ -} +final class NotImplementedException extends RuntimeException {} diff --git a/src/ExistingMessagesConsumer.php b/src/ExistingMessagesConsumer.php index 16628f3..0a8d214 100644 --- a/src/ExistingMessagesConsumer.php +++ b/src/ExistingMessagesConsumer.php @@ -18,9 +18,8 @@ final class ExistingMessagesConsumer public function __construct( private readonly QueueProviderInterface $queueProvider, - private readonly MessageSerializerInterface $serializer - ) { - } + private readonly MessageSerializerInterface $serializer, + ) {} /** * @param callable(MessageInterface): bool $callback @@ -51,7 +50,7 @@ function (AMQPMessage $amqpMessage) use ($callback, $channel): void { throw $exception; } - } + }, ); do { diff --git a/src/Middleware/DelayMiddleware.php b/src/Middleware/DelayMiddleware.php index b6a1c5a..2419ea4 100644 --- a/src/Middleware/DelayMiddleware.php +++ b/src/Middleware/DelayMiddleware.php @@ -11,9 +11,7 @@ final class DelayMiddleware implements PushMiddlewareInterface { - public function __construct(private float $delayInSeconds) - { - } + public function __construct(private float $delayInSeconds) {} /** * @param float $seconds diff --git a/src/QueueProvider.php b/src/QueueProvider.php index 7bd41f3..7ed1f1e 100644 --- a/src/QueueProvider.php +++ b/src/QueueProvider.php @@ -24,13 +24,7 @@ public function __construct( private QueueSettingsInterface $queueSettings, private ?ExchangeSettingsInterface $exchangeSettings = null, private array $messageProperties = [], - ) { - } - - public function __clone() - { - $this->channelId = null; - } + ) {} public function __destruct() { @@ -39,6 +33,11 @@ public function __destruct() } } + public function __clone() + { + $this->channelId = null; + } + /** * Returns an AMQPChannel instance. * IMPORTANT: Do NOT memorise the channel instance, as this will cause memory leaks on channel close! diff --git a/src/Settings/Exchange.php b/src/Settings/Exchange.php index d01acfc..a49f40e 100644 --- a/src/Settings/Exchange.php +++ b/src/Settings/Exchange.php @@ -18,9 +18,8 @@ public function __construct( private bool $internal = false, private bool $nowait = false, private AMQPTable|array $arguments = [], - private ?int $ticket = null - ) { - } + private ?int $ticket = null, + ) {} public function getArguments(): AMQPTable|array { diff --git a/src/Settings/ExchangeSettingsInterface.php b/src/Settings/ExchangeSettingsInterface.php index 200ca6c..b1c30b2 100644 --- a/src/Settings/ExchangeSettingsInterface.php +++ b/src/Settings/ExchangeSettingsInterface.php @@ -5,6 +5,8 @@ namespace Yiisoft\Queue\Amqp\Settings; use PhpAmqpLib\Wire\AMQPTable; +use PhpAmqpLib\Channel\AMQPChannel; +use Yiisoft\Queue\Amqp\QueueProvider; interface ExchangeSettingsInterface { @@ -27,9 +29,9 @@ public function hasNowait(): bool; public function isPassive(): bool; /** - * Positional arguments to be used with {@see \PhpAmqpLib\Channel\AMQPChannel::exchange_declare()} + * Positional arguments to be used with {@see AMQPChannel::exchange_declare()} * - * @see \Yiisoft\Queue\Amqp\QueueProvider::getChannel() + * @see QueueProvider::getChannel() * * @return (AMQPTable|array|bool|int|string|null)[] * diff --git a/src/Settings/QosSettings.php b/src/Settings/QosSettings.php index ba744e9..c7fcb79 100644 --- a/src/Settings/QosSettings.php +++ b/src/Settings/QosSettings.php @@ -5,11 +5,12 @@ namespace Yiisoft\Queue\Amqp\Settings; use InvalidArgumentException; +use PhpAmqpLib\Channel\AMQPChannel; /** * Quality of Service settings for AMQP consumers. * - * @see \PhpAmqpLib\Channel\AMQPChannel::basic_qos() + * @see AMQPChannel::basic_qos() */ final class QosSettings { diff --git a/src/Settings/Queue.php b/src/Settings/Queue.php index 9a96dde..30e6fcf 100644 --- a/src/Settings/Queue.php +++ b/src/Settings/Queue.php @@ -19,8 +19,7 @@ public function __construct( private AMQPTable|array $arguments = [], private ?int $ticket = null, private ?QosSettings $qosSettings = null, - ) { - } + ) {} public function getArguments(): AMQPTable|array { diff --git a/src/Settings/QueueSettingsInterface.php b/src/Settings/QueueSettingsInterface.php index 2850bb7..b07e9bd 100644 --- a/src/Settings/QueueSettingsInterface.php +++ b/src/Settings/QueueSettingsInterface.php @@ -5,6 +5,8 @@ namespace Yiisoft\Queue\Amqp\Settings; use PhpAmqpLib\Wire\AMQPTable; +use PhpAmqpLib\Channel\AMQPChannel; +use Yiisoft\Queue\Amqp\QueueProvider; interface QueueSettingsInterface { @@ -27,9 +29,9 @@ public function hasNowait(): bool; public function isPassive(): bool; /** - * Returns positional arguments to be used with {@see \PhpAmqpLib\Channel\AMQPChannel::queue_declare()} + * Returns positional arguments to be used with {@see AMQPChannel::queue_declare()} * - * @see \Yiisoft\Queue\Amqp\QueueProvider::getChannel() + * @see QueueProvider::getChannel() * * @return (AMQPTable|array|bool|int|string|null)[] * diff --git a/tests/Benchmark/QueuePushBench.php b/tests/Benchmark/QueuePushBench.php index 9120462..ab45a6c 100644 --- a/tests/Benchmark/QueuePushBench.php +++ b/tests/Benchmark/QueuePushBench.php @@ -36,7 +36,7 @@ public function __construct() getenv('RABBITMQ_USER'), getenv('RABBITMQ_PASSWORD'), ), - new QueueSettings() + new QueueSettings(), ); $adapter = new Adapter($queueProvider, $serializer, $loop); @@ -76,6 +76,6 @@ public function benchPushBatch(): void public function cleanupQueue(): void { - $this->adapter->runExisting(static fn (): bool => true); + $this->adapter->runExisting(static fn(): bool => true); } } diff --git a/tests/Integration/ConsumeExistingMessagesTest.php b/tests/Integration/ConsumeExistingMessagesTest.php index 29d9825..377aaf0 100644 --- a/tests/Integration/ConsumeExistingMessagesTest.php +++ b/tests/Integration/ConsumeExistingMessagesTest.php @@ -26,7 +26,7 @@ public function testConsumeExistingMessages(): void getenv('RABBITMQ_USER'), getenv('RABBITMQ_PASSWORD'), ), - new QueueSettings() + new QueueSettings(), ); $adapter = new Adapter($queueProvider, $serializer, $loop); @@ -39,7 +39,7 @@ public function testConsumeExistingMessages(): void sleep(1); $processingCount = 0; - $adapter->runExisting(static function() use (&$processingCount): bool { + $adapter->runExisting(static function () use (&$processingCount): bool { $processingCount++; return true; }); @@ -58,7 +58,7 @@ public function testConsumeExistingMessagesByOne(): void getenv('RABBITMQ_USER'), getenv('RABBITMQ_PASSWORD'), ), - new QueueSettings() + new QueueSettings(), ); $adapter = new Adapter($queueProvider, $serializer, $loop); diff --git a/tests/Integration/DelayMiddlewareTest.php b/tests/Integration/DelayMiddlewareTest.php index df6ff2d..58fcf91 100644 --- a/tests/Integration/DelayMiddlewareTest.php +++ b/tests/Integration/DelayMiddlewareTest.php @@ -26,6 +26,7 @@ use Yiisoft\Queue\Queue; use Yiisoft\Queue\Worker\WorkerInterface; use Yiisoft\Test\Support\Container\SimpleContainer; +use LogicException; final class DelayMiddlewareTest extends TestCase { @@ -79,7 +80,7 @@ public function testMainFlowWithFakeAdapter(): void ); $queue = $this->makeQueue($adapter, new DelayMiddleware(3)); - $this->expectException(\LogicException::class); + $this->expectException(LogicException::class); $this->expectExceptionMessage('Method not implemented'); $queue->push( Message::fromPayload('simple', 'test-delay-middleware-main'), diff --git a/tests/Integration/TestCase.php b/tests/Integration/TestCase.php index bfc5f65..96104ab 100644 --- a/tests/Integration/TestCase.php +++ b/tests/Integration/TestCase.php @@ -7,6 +7,11 @@ use Symfony\Component\Process\Process; use Yiisoft\Queue\Amqp\Tests\Support\FileHelper; use Yiisoft\Queue\Amqp\Tests\Support\MainTestCase; +use Exception; + +use function dirname; + +use const PHP_BINARY; abstract class TestCase extends MainTestCase { @@ -51,7 +56,7 @@ protected function queueListen(?string $queue = null): void usleep(500000); if (!$process->isRunning()) { - throw new \Exception('Failed to start queue listener process'); + throw new Exception('Failed to start queue listener process'); } } } diff --git a/tests/Support/ExtendedSimpleMessageHandler.php b/tests/Support/ExtendedSimpleMessageHandler.php index 5bb3d60..35d48d7 100644 --- a/tests/Support/ExtendedSimpleMessageHandler.php +++ b/tests/Support/ExtendedSimpleMessageHandler.php @@ -6,14 +6,16 @@ use Yiisoft\Queue\Message\MessageInterface; +use function is_array; +use function is_int; +use function is_string; + /** * Accepts any values from the queue and writes to the file */ final class ExtendedSimpleMessageHandler { - public function __construct(private readonly FileHelper $fileHelper) - { - } + public function __construct(private readonly FileHelper $fileHelper) {} public function handle(MessageInterface $message): void { diff --git a/tests/Support/FakeAdapter.php b/tests/Support/FakeAdapter.php index 888240e..3cf1656 100644 --- a/tests/Support/FakeAdapter.php +++ b/tests/Support/FakeAdapter.php @@ -19,8 +19,7 @@ public function __construct( private readonly QueueProviderInterface $queueProvider, private readonly MessageSerializerInterface $serializer, private readonly LoopInterface $loop, - ) { - } + ) {} public function runExisting(callable $handlerCallback): void { diff --git a/tests/Support/FileHelper.php b/tests/Support/FileHelper.php index 8a22b8e..f8e5cab 100644 --- a/tests/Support/FileHelper.php +++ b/tests/Support/FileHelper.php @@ -6,6 +6,8 @@ use RuntimeException; +use function dirname; + final class FileHelper { /** diff --git a/tests/Support/MainTestCase.php b/tests/Support/MainTestCase.php index 73e07b7..65801d3 100644 --- a/tests/Support/MainTestCase.php +++ b/tests/Support/MainTestCase.php @@ -18,7 +18,7 @@ protected function createConnection(): AMQPStreamConnection getenv('RABBITMQ_HOST'), getenv('RABBITMQ_PORT'), getenv('RABBITMQ_USER'), - getenv('RABBITMQ_PASSWORD') + getenv('RABBITMQ_PASSWORD'), ); } diff --git a/tests/Support/SimpleMessageHandler.php b/tests/Support/SimpleMessageHandler.php index f22a73a..26ddb95 100644 --- a/tests/Support/SimpleMessageHandler.php +++ b/tests/Support/SimpleMessageHandler.php @@ -6,11 +6,11 @@ use Yiisoft\Queue\Message\MessageInterface; +use function is_string; + final class SimpleMessageHandler { - public function __construct(private readonly FileHelper $fileHelper) - { - } + public function __construct(private readonly FileHelper $fileHelper) {} public function __invoke(MessageInterface $message): void { diff --git a/tests/Support/TestMessage.php b/tests/Support/TestMessage.php index 9abe407..474e37b 100644 --- a/tests/Support/TestMessage.php +++ b/tests/Support/TestMessage.php @@ -16,8 +16,7 @@ public function __construct( private readonly string $type, private readonly bool|int|float|string|array|null $payload, private readonly array $meta = [], - ) { - } + ) {} public static function fromPayload(string $type, bool|int|float|string|array|null $payload): static { diff --git a/tests/Unit/DelayMiddlewareTest.php b/tests/Unit/DelayMiddlewareTest.php index ee9cd45..39b9a1e 100644 --- a/tests/Unit/DelayMiddlewareTest.php +++ b/tests/Unit/DelayMiddlewareTest.php @@ -32,7 +32,7 @@ public function testImmutable(): void public function testProcessPushAddsDelayEnvelope(): void { $message = Message::fromPayload('simple', null); - $handler = new class () implements PushHandlerInterface { + $handler = new class implements PushHandlerInterface { public function handlePush(MessageInterface $message): MessageInterface { return $message; @@ -48,7 +48,7 @@ public function handlePush(MessageInterface $message): MessageInterface public function testProcessPushSkipsNonPositiveDelay(): void { $message = Message::fromPayload('simple', null); - $handler = new class () implements PushHandlerInterface { + $handler = new class implements PushHandlerInterface { public function handlePush(MessageInterface $message): MessageInterface { return $message; diff --git a/tests/Unit/ExchangeSettingsTest.php b/tests/Unit/ExchangeSettingsTest.php index a667a87..23c1002 100644 --- a/tests/Unit/ExchangeSettingsTest.php +++ b/tests/Unit/ExchangeSettingsTest.php @@ -21,7 +21,7 @@ public function testCommonSettings(): void nowait: true, arguments: new AMQPTable([ 'alternate-exchange' => 'yii-queue-test-common-settings-alt', - ]) + ]), ); self::assertTrue($exchangeSettings->isDurable()); diff --git a/tests/Unit/QueueProviderTest.php b/tests/Unit/QueueProviderTest.php index 81ffd6c..76cb2bd 100644 --- a/tests/Unit/QueueProviderTest.php +++ b/tests/Unit/QueueProviderTest.php @@ -16,6 +16,8 @@ use Yiisoft\Queue\Message\Serializer\MessageSerializer; use Yiisoft\Queue\Amqp\Tests\Support\TestMessage as Message; +use const JSON_THROW_ON_ERROR; + final class QueueProviderTest extends UnitTestCase { public function testWithQueueAndExchangeSettings(): void @@ -30,10 +32,10 @@ public function testWithQueueAndExchangeSettings(): void $adapter = new Adapter( $queueProvider ->withQueueSettings( - new QueueSettings($this->queueName) + new QueueSettings($this->queueName), ) ->withExchangeSettings( - new ExchangeSettings($this->exchangeName) + new ExchangeSettings($this->exchangeName), ), new MessageSerializer(new JsonMessageEncoder()), $this->getLoop(), @@ -44,7 +46,7 @@ public function testWithQueueAndExchangeSettings(): void $fileHelper = new FileHelper(); $time = time(); $queue->push( - Message::fromPayload('ext-simple', ['file_name' => 'test-with-queue-settings', 'payload' => ['time' => $time]]) + Message::fromPayload('ext-simple', ['file_name' => 'test-with-queue-settings', 'payload' => ['time' => $time]]), ); $message = $this @@ -76,10 +78,10 @@ public function testWithQueueNameExchangeDeclaredException(): void new Adapter( $queueProvider ->withQueueSettings( - new QueueSettings('yii-queue-test-with-queue-name') + new QueueSettings('yii-queue-test-with-queue-name'), ) ->withExchangeSettings( - new ExchangeSettings('yii-queue-test-with-queue-name') + new ExchangeSettings('yii-queue-test-with-queue-name'), ) ->withQueueName('yii-queue-test-queue-name'), new MessageSerializer(new JsonMessageEncoder()), @@ -92,7 +94,7 @@ public function testImmutable(): void $queueSettings = $this->createMock(QueueSettingsInterface::class); $queueProvider = new QueueProvider( $this->createConnection(), - $queueSettings + $queueSettings, ); self::assertNotSame($queueProvider, $queueProvider->withQueueSettings($queueSettings)); diff --git a/tests/Unit/QueueSettingsTest.php b/tests/Unit/QueueSettingsTest.php index 15695be..69e4fa8 100644 --- a/tests/Unit/QueueSettingsTest.php +++ b/tests/Unit/QueueSettingsTest.php @@ -52,7 +52,7 @@ public function testCommonSettings(): void 'x-dead-letter-exchange' => 'yii-queue-test-queue-common-settings-dead-letter-exc', 'x-message-ttl' => 15000, 'x-expires' => 16000, - ]) + ]), ); self::assertTrue($queueSettings->isDurable()); @@ -92,11 +92,11 @@ public function testArgumentsXExpires(): void queueName: 'yii-queue-test-queue-settings-arg', arguments: new AMQPTable([ 'x-expires' => 1600, - ]) - ) + ]), + ), ) ->withExchangeSettings( - new ExchangeSettings('yii-queue-test-queue-settings-arg') + new ExchangeSettings('yii-queue-test-queue-settings-arg'), ), new MessageSerializer(new JsonMessageEncoder()), $this->getLoop(), @@ -104,7 +104,7 @@ public function testArgumentsXExpires(): void $this->getQueueWithAdapter($adapter) ->push( - Message::fromPayload('ext-simple', ['payload' => time()]) + Message::fromPayload('ext-simple', ['payload' => time()]), ); sleep(2); diff --git a/tests/Unit/QueueTest.php b/tests/Unit/QueueTest.php index 1b4239f..7b92851 100644 --- a/tests/Unit/QueueTest.php +++ b/tests/Unit/QueueTest.php @@ -68,7 +68,7 @@ public function testRun(): void $queue = $this->getDefaultQueue($this->getAdapter()); $queue->push( - Message::fromPayload('ext-simple', ['file_name' => $fileName, 'payload' => ['time' => $time]]) + Message::fromPayload('ext-simple', ['file_name' => $fileName, 'payload' => ['time' => $time]]), ); self::assertNull($fileHelper->get($fileName)); @@ -105,7 +105,7 @@ public function testListenWithException(): void $queue->listen(); - $this->expectExceptionMessage((string)$time); + $this->expectExceptionMessage((string) $time); } public function testListen(): void @@ -127,23 +127,18 @@ public function testListen(): void $queue = $this->getDefaultQueue($adapter); $queue->push( - Message::fromPayload('ext-simple', ['file_name' => 'test-listen' . $time, 'payload' => ['time' => $time]]) + Message::fromPayload('ext-simple', ['file_name' => 'test-listen' . $time, 'payload' => ['time' => $time]]), ); $queue->listen(); } - private function getDefaultQueue(AdapterInterface $adapter): Queue - { - return $this->getQueueWithAdapter($adapter); - } - public function testImmutable(): void { $queueProvider = $this->createMock(QueueProviderInterface::class); $adapter = new Adapter( $queueProvider, $this->createMock(MessageSerializerInterface::class), - $this->createMock(LoopInterface::class) + $this->createMock(LoopInterface::class), ); self::assertNotSame($adapter, $adapter->withChannel('test')); @@ -242,7 +237,7 @@ public function testPushUsesStringExpirationForDelayedMessage(): void $adapter = new Adapter( $queueProvider, $serializer, - $this->createMock(LoopInterface::class) + $this->createMock(LoopInterface::class), ); self::assertSame($message, $adapter->push($message)); @@ -295,4 +290,9 @@ public function testSubscribeSkipsBasicQosWhenNotConfigured(): void $adapter = new Adapter($queueProvider, $this->createMock(MessageSerializerInterface::class), $loop); $adapter->subscribe(static fn() => null); } + + private function getDefaultQueue(AdapterInterface $adapter): Queue + { + return $this->getQueueWithAdapter($adapter); + } } diff --git a/tests/Unit/UnitTestCase.php b/tests/Unit/UnitTestCase.php index e4008af..9c1193b 100644 --- a/tests/Unit/UnitTestCase.php +++ b/tests/Unit/UnitTestCase.php @@ -32,18 +32,22 @@ use Yiisoft\Queue\Worker\WorkerInterface; use Yiisoft\Test\Support\Container\SimpleContainer; +use function is_array; +use function is_int; +use function is_string; + /** * Test case for unit tests */ abstract class UnitTestCase extends MainTestCase { - protected Queue|null $queue = null; + public ?QueueSettings $queueSettings = null; + public ?QueueProvider $queueProvider = null; + protected ?Queue $queue = null; protected ?WorkerInterface $worker = null; protected ?ContainerInterface $container = null; protected ?AdapterInterface $adapter = null; protected ?LoopInterface $loop = null; - public ?QueueSettings $queueSettings = null; - public ?QueueProvider $queueProvider = null; protected function setUp(): void {