From c48584450c0b01137978f69d6b4e0a6662de3b5a Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 12 Dec 2024 21:36:18 +0300 Subject: [PATCH 1/6] Allow to use backed enumerations as channel name --- src/Adapter/AdapterInterface.php | 3 ++- src/Adapter/SynchronousAdapter.php | 5 +++- stubs/StubAdapter.php | 6 ++--- tests/App/FakeAdapter.php | 6 ++--- tests/Benchmark/Support/VoidAdapter.php | 3 ++- .../{ => Adapter}/SynchronousAdapterTest.php | 25 +++++++++++++++++-- tests/Unit/Stubs/StubAdapterTest.php | 18 +++++++++++++ tests/Unit/Support/IntEnum.php | 11 ++++++++ tests/Unit/Support/StringEnum.php | 11 ++++++++ 9 files changed, 77 insertions(+), 11 deletions(-) rename tests/Unit/{ => Adapter}/SynchronousAdapterTest.php (77%) create mode 100644 tests/Unit/Support/IntEnum.php create mode 100644 tests/Unit/Support/StringEnum.php diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index 0d8ceeda..fd6ca02a 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -4,6 +4,7 @@ namespace Yiisoft\Queue\Adapter; +use BackedEnum; use InvalidArgumentException; use Yiisoft\Queue\Enum\JobStatus; use Yiisoft\Queue\Message\MessageInterface; @@ -40,7 +41,7 @@ public function push(MessageInterface $message): MessageInterface; */ public function subscribe(callable $handlerCallback): void; - public function withChannel(string $channel): self; + public function withChannel(string|BackedEnum $channel): self; public function getChannelName(): string; } diff --git a/src/Adapter/SynchronousAdapter.php b/src/Adapter/SynchronousAdapter.php index 84148941..da19d5c7 100644 --- a/src/Adapter/SynchronousAdapter.php +++ b/src/Adapter/SynchronousAdapter.php @@ -4,6 +4,7 @@ namespace Yiisoft\Queue\Adapter; +use BackedEnum; use InvalidArgumentException; use Yiisoft\Queue\Enum\JobStatus; use Yiisoft\Queue\Message\MessageInterface; @@ -74,8 +75,10 @@ public function subscribe(callable $handlerCallback): void $this->runExisting($handlerCallback); } - public function withChannel(string $channel): self + public function withChannel(string|BackedEnum $channel): self { + $channel = $channel instanceof BackedEnum ? (string) $channel->value : $channel; + if ($channel === $this->channel) { return $this; } diff --git a/stubs/StubAdapter.php b/stubs/StubAdapter.php index 0a8e06b2..3d7c7a9a 100644 --- a/stubs/StubAdapter.php +++ b/stubs/StubAdapter.php @@ -4,6 +4,7 @@ namespace Yiisoft\Queue\Stubs; +use BackedEnum; use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\Enum\JobStatus; use Yiisoft\Queue\Message\MessageInterface; @@ -36,11 +37,10 @@ public function subscribe(callable $handlerCallback): void { } - public function withChannel(string $channel): AdapterInterface + public function withChannel(string|BackedEnum $channel): AdapterInterface { $new = clone $this; - $new->channelName = $channel; - + $new->channelName = $channel instanceof BackedEnum ? (string) $channel->value : $channel; return $new; } diff --git a/tests/App/FakeAdapter.php b/tests/App/FakeAdapter.php index aec34910..a8933689 100644 --- a/tests/App/FakeAdapter.php +++ b/tests/App/FakeAdapter.php @@ -4,6 +4,7 @@ namespace Yiisoft\Queue\Tests\App; +use BackedEnum; use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\Enum\JobStatus; use Yiisoft\Queue\Message\MessageInterface; @@ -35,12 +36,11 @@ public function subscribe(callable $handlerCallback): void //skip } - public function withChannel(string $channel): AdapterInterface + public function withChannel(string|BackedEnum $channel): AdapterInterface { $instance = clone $this; $instance->pushMessages = []; - $instance->channel = $channel; - + $instance->channel = $channel instanceof BackedEnum ? (string) $channel->value : $channel; return $instance; } diff --git a/tests/Benchmark/Support/VoidAdapter.php b/tests/Benchmark/Support/VoidAdapter.php index b1a42966..6d074811 100644 --- a/tests/Benchmark/Support/VoidAdapter.php +++ b/tests/Benchmark/Support/VoidAdapter.php @@ -4,6 +4,7 @@ namespace Yiisoft\Queue\Tests\Benchmark\Support; +use BackedEnum; use InvalidArgumentException; use RuntimeException; use Yiisoft\Queue\Adapter\AdapterInterface; @@ -45,7 +46,7 @@ public function subscribe(callable $handlerCallback): void throw new RuntimeException('Method is not implemented'); } - public function withChannel(string $channel): AdapterInterface + public function withChannel(string|BackedEnum $channel): AdapterInterface { throw new RuntimeException('Method is not implemented'); } diff --git a/tests/Unit/SynchronousAdapterTest.php b/tests/Unit/Adapter/SynchronousAdapterTest.php similarity index 77% rename from tests/Unit/SynchronousAdapterTest.php rename to tests/Unit/Adapter/SynchronousAdapterTest.php index 6e913932..619a0288 100644 --- a/tests/Unit/SynchronousAdapterTest.php +++ b/tests/Unit/Adapter/SynchronousAdapterTest.php @@ -2,13 +2,19 @@ declare(strict_types=1); -namespace Yiisoft\Queue\Tests\Unit; +namespace Yiisoft\Queue\Tests\Unit\Adapter; +use PHPUnit\Framework\Attributes\DataProvider; +use Yiisoft\Queue\Adapter\SynchronousAdapter; use Yiisoft\Queue\Enum\JobStatus; +use Yiisoft\Queue\Message\IdEnvelope; use Yiisoft\Queue\Message\Message; use Yiisoft\Queue\QueueInterface; +use Yiisoft\Queue\Stubs\StubQueue; +use Yiisoft\Queue\Stubs\StubWorker; use Yiisoft\Queue\Tests\TestCase; -use Yiisoft\Queue\Message\IdEnvelope; +use Yiisoft\Queue\Tests\Unit\Support\IntEnum; +use Yiisoft\Queue\Tests\Unit\Support\StringEnum; final class SynchronousAdapterTest extends TestCase { @@ -92,4 +98,19 @@ public function testStatusNotMessage(): void $this->expectExceptionMessage('There is no message with the given ID.'); $adapter->status('1'); } + + public static function dataWithChannel(): iterable + { + yield 'string' => ['test', 'test']; + yield 'string-enum' => ['red', StringEnum::RED]; + yield 'integer-enum' => ['1', IntEnum::ONE]; + } + + #[DataProvider('dataWithChannel')] + public function testWithChannel(string $expected, mixed $channel): void + { + $adapter = (new SynchronousAdapter(new StubWorker(), new StubQueue()))->withChannel($channel); + + $this->assertSame($expected, $adapter->getChannelName()); + } } diff --git a/tests/Unit/Stubs/StubAdapterTest.php b/tests/Unit/Stubs/StubAdapterTest.php index b7337967..65e36b2a 100644 --- a/tests/Unit/Stubs/StubAdapterTest.php +++ b/tests/Unit/Stubs/StubAdapterTest.php @@ -4,9 +4,12 @@ namespace Yiisoft\Queue\Tests\Unit\Stubs; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Yiisoft\Queue\Message\Message; use Yiisoft\Queue\Stubs\StubAdapter; +use Yiisoft\Queue\Tests\Unit\Support\IntEnum; +use Yiisoft\Queue\Tests\Unit\Support\StringEnum; final class StubAdapterTest extends TestCase { @@ -21,4 +24,19 @@ public function testBase(): void $adapter->runExisting(static fn() => null); $adapter->subscribe(static fn() => null); } + + public static function dataWithChannel(): iterable + { + yield 'string' => ['test', 'test']; + yield 'string-enum' => ['red', StringEnum::RED]; + yield 'integer-enum' => ['1', IntEnum::ONE]; + } + + #[DataProvider('dataWithChannel')] + public function testWithChannel(string $expected, mixed $channel): void + { + $adapter = (new StubAdapter())->withChannel($channel); + + $this->assertSame($expected, $adapter->getChannelName()); + } } diff --git a/tests/Unit/Support/IntEnum.php b/tests/Unit/Support/IntEnum.php new file mode 100644 index 00000000..9f8cdb85 --- /dev/null +++ b/tests/Unit/Support/IntEnum.php @@ -0,0 +1,11 @@ + Date: Thu, 12 Dec 2024 22:26:36 +0300 Subject: [PATCH 2/6] adapter constructor --- composer.json | 2 +- src/Adapter/SynchronousAdapter.php | 7 +++++-- src/ChannelNormalizer.php | 18 ++++++++++++++++++ stubs/StubAdapter.php | 11 ++++++++--- tests/Unit/Adapter/SynchronousAdapterTest.php | 12 ++++++++++-- tests/Unit/Stubs/StubAdapterTest.php | 12 ++++++++++-- 6 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 src/ChannelNormalizer.php diff --git a/composer.json b/composer.json index 9812ea48..a6fe193a 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "psr/container": "^1.0|^2.0", "psr/log": "^2.0|^3.0", "symfony/console": "^5.4|^6.0", - "yiisoft/definitions": "^1.0|^2.0|^3.0", + "yiisoft/definitions": "dev-fix-union as 3.0.1", "yiisoft/factory": "^1.3", "yiisoft/friendly-exception": "^1.0", "yiisoft/injector": "^1.0" diff --git a/src/Adapter/SynchronousAdapter.php b/src/Adapter/SynchronousAdapter.php index da19d5c7..82ebde2a 100644 --- a/src/Adapter/SynchronousAdapter.php +++ b/src/Adapter/SynchronousAdapter.php @@ -6,6 +6,7 @@ use BackedEnum; use InvalidArgumentException; +use Yiisoft\Queue\ChannelNormalizer; use Yiisoft\Queue\Enum\JobStatus; use Yiisoft\Queue\Message\MessageInterface; use Yiisoft\Queue\QueueInterface; @@ -16,12 +17,14 @@ final class SynchronousAdapter implements AdapterInterface { private array $messages = []; private int $current = 0; + private string $channel; public function __construct( private WorkerInterface $worker, private QueueInterface $queue, - private string $channel = QueueInterface::DEFAULT_CHANNEL_NAME, + string|BackedEnum $channel = QueueInterface::DEFAULT_CHANNEL_NAME, ) { + $this->channel = ChannelNormalizer::normalize($channel); } public function __destruct() @@ -77,7 +80,7 @@ public function subscribe(callable $handlerCallback): void public function withChannel(string|BackedEnum $channel): self { - $channel = $channel instanceof BackedEnum ? (string) $channel->value : $channel; + $channel = ChannelNormalizer::normalize($channel); if ($channel === $this->channel) { return $this; diff --git a/src/ChannelNormalizer.php b/src/ChannelNormalizer.php new file mode 100644 index 00000000..1b178188 --- /dev/null +++ b/src/ChannelNormalizer.php @@ -0,0 +1,18 @@ +value : $channel; + } +} diff --git a/stubs/StubAdapter.php b/stubs/StubAdapter.php index 3d7c7a9a..1142f173 100644 --- a/stubs/StubAdapter.php +++ b/stubs/StubAdapter.php @@ -6,6 +6,7 @@ use BackedEnum; use Yiisoft\Queue\Adapter\AdapterInterface; +use Yiisoft\Queue\ChannelNormalizer; use Yiisoft\Queue\Enum\JobStatus; use Yiisoft\Queue\Message\MessageInterface; use Yiisoft\Queue\QueueInterface; @@ -15,8 +16,12 @@ */ final class StubAdapter implements AdapterInterface { - public function __construct(private string $channelName = QueueInterface::DEFAULT_CHANNEL_NAME) - { + private string $channelName; + + public function __construct( + string|BackedEnum $channelName = QueueInterface::DEFAULT_CHANNEL_NAME + ) { + $this->channelName = ChannelNormalizer::normalize($channelName); } public function runExisting(callable $handlerCallback): void @@ -40,7 +45,7 @@ public function subscribe(callable $handlerCallback): void public function withChannel(string|BackedEnum $channel): AdapterInterface { $new = clone $this; - $new->channelName = $channel instanceof BackedEnum ? (string) $channel->value : $channel; + $new->channelName = ChannelNormalizer::normalize($channel); return $new; } diff --git a/tests/Unit/Adapter/SynchronousAdapterTest.php b/tests/Unit/Adapter/SynchronousAdapterTest.php index 619a0288..35e0f0a5 100644 --- a/tests/Unit/Adapter/SynchronousAdapterTest.php +++ b/tests/Unit/Adapter/SynchronousAdapterTest.php @@ -99,18 +99,26 @@ public function testStatusNotMessage(): void $adapter->status('1'); } - public static function dataWithChannel(): iterable + public static function dataChannels(): iterable { yield 'string' => ['test', 'test']; yield 'string-enum' => ['red', StringEnum::RED]; yield 'integer-enum' => ['1', IntEnum::ONE]; } - #[DataProvider('dataWithChannel')] + #[DataProvider('dataChannels')] public function testWithChannel(string $expected, mixed $channel): void { $adapter = (new SynchronousAdapter(new StubWorker(), new StubQueue()))->withChannel($channel); $this->assertSame($expected, $adapter->getChannelName()); } + + #[DataProvider('dataChannels')] + public function testChannelInConstructor(string $expected, mixed $channel): void + { + $adapter = new SynchronousAdapter(new StubWorker(), new StubQueue(), $channel); + + $this->assertSame($expected, $adapter->getChannelName()); + } } diff --git a/tests/Unit/Stubs/StubAdapterTest.php b/tests/Unit/Stubs/StubAdapterTest.php index 65e36b2a..aad5c799 100644 --- a/tests/Unit/Stubs/StubAdapterTest.php +++ b/tests/Unit/Stubs/StubAdapterTest.php @@ -25,18 +25,26 @@ public function testBase(): void $adapter->subscribe(static fn() => null); } - public static function dataWithChannel(): iterable + public static function dataChannels(): iterable { yield 'string' => ['test', 'test']; yield 'string-enum' => ['red', StringEnum::RED]; yield 'integer-enum' => ['1', IntEnum::ONE]; } - #[DataProvider('dataWithChannel')] + #[DataProvider('dataChannels')] public function testWithChannel(string $expected, mixed $channel): void { $adapter = (new StubAdapter())->withChannel($channel); $this->assertSame($expected, $adapter->getChannelName()); } + + #[DataProvider('dataChannels')] + public function testChannelInConstructor(string $expected, mixed $channel): void + { + $adapter = new StubAdapter($channel); + + $this->assertSame($expected, $adapter->getChannelName()); + } } From 6effbf27e5b3d3c89ea5c91566960c0c43b9930d Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 12 Dec 2024 22:37:57 +0300 Subject: [PATCH 3/6] providers --- composer.json | 2 +- src/Debug/QueueProviderInterfaceProxy.php | 5 ++-- src/Provider/AdapterFactoryQueueProvider.php | 10 +++++-- src/Provider/ChannelNotFoundException.php | 6 ++-- src/Provider/CompositeQueueProvider.php | 5 ++-- src/Provider/PrototypeQueueProvider.php | 5 ++-- src/Provider/QueueProviderInterface.php | 9 +++--- .../AdapterFactoryQueueProviderTest.php | 17 +++++++++++ .../Provider/ChannelNotFoundExceptionTest.php | 30 +++++++++++++++++++ 9 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 tests/Unit/Provider/ChannelNotFoundExceptionTest.php diff --git a/composer.json b/composer.json index a6fe193a..9812ea48 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "psr/container": "^1.0|^2.0", "psr/log": "^2.0|^3.0", "symfony/console": "^5.4|^6.0", - "yiisoft/definitions": "dev-fix-union as 3.0.1", + "yiisoft/definitions": "^1.0|^2.0|^3.0", "yiisoft/factory": "^1.3", "yiisoft/friendly-exception": "^1.0", "yiisoft/injector": "^1.0" diff --git a/src/Debug/QueueProviderInterfaceProxy.php b/src/Debug/QueueProviderInterfaceProxy.php index 5f00096e..22ce1307 100644 --- a/src/Debug/QueueProviderInterfaceProxy.php +++ b/src/Debug/QueueProviderInterfaceProxy.php @@ -4,6 +4,7 @@ namespace Yiisoft\Queue\Debug; +use BackedEnum; use Yiisoft\Queue\Provider\QueueProviderInterface; use Yiisoft\Queue\QueueInterface; @@ -15,13 +16,13 @@ public function __construct( ) { } - public function get(string $channel): QueueInterface + public function get(string|BackedEnum $channel): QueueInterface { $queue = $this->queueProvider->get($channel); return new QueueDecorator($queue, $this->collector); } - public function has(string $channel): bool + public function has(string|BackedEnum $channel): bool { return $this->queueProvider->has($channel); } diff --git a/src/Provider/AdapterFactoryQueueProvider.php b/src/Provider/AdapterFactoryQueueProvider.php index 7f9cca30..36c2a193 100644 --- a/src/Provider/AdapterFactoryQueueProvider.php +++ b/src/Provider/AdapterFactoryQueueProvider.php @@ -4,10 +4,12 @@ namespace Yiisoft\Queue\Provider; +use BackedEnum; use Psr\Container\ContainerInterface; use Yiisoft\Definitions\Exception\InvalidConfigException; use Yiisoft\Factory\StrictFactory; use Yiisoft\Queue\Adapter\AdapterInterface; +use Yiisoft\Queue\ChannelNormalizer; use Yiisoft\Queue\QueueInterface; use function array_key_exists; @@ -50,17 +52,21 @@ public function __construct( } } - public function get(string $channel): QueueInterface + public function get(string|BackedEnum $channel): QueueInterface { + $channel = ChannelNormalizer::normalize($channel); + $queue = $this->getOrTryToCreate($channel); if ($queue === null) { throw new ChannelNotFoundException($channel); } + return $queue; } - public function has(string $channel): bool + public function has(string|BackedEnum $channel): bool { + $channel = ChannelNormalizer::normalize($channel); return $this->factory->has($channel); } diff --git a/src/Provider/ChannelNotFoundException.php b/src/Provider/ChannelNotFoundException.php index 2538cda7..ef9b3ace 100644 --- a/src/Provider/ChannelNotFoundException.php +++ b/src/Provider/ChannelNotFoundException.php @@ -4,8 +4,10 @@ namespace Yiisoft\Queue\Provider; +use BackedEnum; use LogicException; use Throwable; +use Yiisoft\Queue\ChannelNormalizer; use function sprintf; @@ -14,10 +16,10 @@ */ final class ChannelNotFoundException extends LogicException implements QueueProviderException { - public function __construct(string $channel, int $code = 0, ?Throwable $previous = null) + public function __construct(string|BackedEnum $channel, int $code = 0, ?Throwable $previous = null) { parent::__construct( - sprintf('Channel "%s" not found.', $channel), + sprintf('Channel "%s" not found.', ChannelNormalizer::normalize($channel)), $code, $previous, ); diff --git a/src/Provider/CompositeQueueProvider.php b/src/Provider/CompositeQueueProvider.php index cd7f36ca..f699d256 100644 --- a/src/Provider/CompositeQueueProvider.php +++ b/src/Provider/CompositeQueueProvider.php @@ -4,6 +4,7 @@ namespace Yiisoft\Queue\Provider; +use BackedEnum; use Yiisoft\Queue\QueueInterface; /** @@ -25,7 +26,7 @@ public function __construct( $this->providers = $providers; } - public function get(string $channel): QueueInterface + public function get(string|BackedEnum $channel): QueueInterface { foreach ($this->providers as $provider) { if ($provider->has($channel)) { @@ -35,7 +36,7 @@ public function get(string $channel): QueueInterface throw new ChannelNotFoundException($channel); } - public function has(string $channel): bool + public function has(string|BackedEnum $channel): bool { foreach ($this->providers as $provider) { if ($provider->has($channel)) { diff --git a/src/Provider/PrototypeQueueProvider.php b/src/Provider/PrototypeQueueProvider.php index 4b7a2d4b..929d124a 100644 --- a/src/Provider/PrototypeQueueProvider.php +++ b/src/Provider/PrototypeQueueProvider.php @@ -4,6 +4,7 @@ namespace Yiisoft\Queue\Provider; +use BackedEnum; use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\QueueInterface; @@ -22,12 +23,12 @@ public function __construct( ) { } - public function get(string $channel): QueueInterface + public function get(string|BackedEnum $channel): QueueInterface { return $this->baseQueue->withAdapter($this->baseAdapter->withChannel($channel)); } - public function has(string $channel): bool + public function has(string|BackedEnum $channel): bool { return true; } diff --git a/src/Provider/QueueProviderInterface.php b/src/Provider/QueueProviderInterface.php index 7d3501b7..2e67a2f1 100644 --- a/src/Provider/QueueProviderInterface.php +++ b/src/Provider/QueueProviderInterface.php @@ -4,6 +4,7 @@ namespace Yiisoft\Queue\Provider; +use BackedEnum; use Yiisoft\Queue\QueueInterface; /** @@ -14,21 +15,21 @@ interface QueueProviderInterface /** * Find a queue by channel name and returns it. * - * @param string $channel Channel name. + * @param string|BackedEnum $channel Channel name. * * @throws InvalidQueueConfigException If the queue configuration is invalid. * @throws ChannelNotFoundException If the channel is not found. * @throws QueueProviderException If the queue provider fails to provide a queue. * @return QueueInterface Queue instance. */ - public function get(string $channel): QueueInterface; + public function get(string|BackedEnum $channel): QueueInterface; /** * Check if a queue with the specified channel name exists. * - * @param string $channel Channel name. + * @param string|BackedEnum $channel Channel name. * * @return bool Whether the queue exists. */ - public function has(string $channel): bool; + public function has(string|BackedEnum $channel): bool; } diff --git a/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php b/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php index 24ca9096..94900a66 100644 --- a/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php +++ b/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php @@ -12,6 +12,7 @@ use Yiisoft\Queue\Provider\InvalidQueueConfigException; use Yiisoft\Queue\Stubs\StubQueue; use Yiisoft\Queue\Stubs\StubAdapter; +use Yiisoft\Queue\Tests\Unit\Support\StringEnum; use function sprintf; @@ -100,4 +101,20 @@ public function testInvalidQueueConfigOnGet(): void ); $provider->get('channel1'); } + + public function testGetHasByStringEnum(): void + { + $provider = new AdapterFactoryQueueProvider( + new StubQueue(), + [ + 'red' => StubAdapter::class, + ], + ); + + $queue = $provider->get(StringEnum::RED); + + $this->assertSame('red', $queue->getChannelName()); + $this->assertTrue($provider->has(StringEnum::RED)); + $this->assertFalse($provider->has(StringEnum::GREEN)); + } } diff --git a/tests/Unit/Provider/ChannelNotFoundExceptionTest.php b/tests/Unit/Provider/ChannelNotFoundExceptionTest.php new file mode 100644 index 00000000..699a94b2 --- /dev/null +++ b/tests/Unit/Provider/ChannelNotFoundExceptionTest.php @@ -0,0 +1,30 @@ + ['channel1', 'channel1']; + yield 'string-enum' => ['red', StringEnum::RED]; + } + + #[DataProvider('dataBase')] + public function testBase(string $expectedChannelName, mixed $channel): void + { + $exception = new ChannelNotFoundException($channel); + + $this->assertSame( + 'Channel "' . $expectedChannelName . '" not found.', + $exception->getMessage(), + ); + } +} From 6cf726cb4b42c7758626d91093610dbb672d83eb Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 12 Dec 2024 19:38:20 +0000 Subject: [PATCH 4/6] Apply fixes from StyleCI --- src/Provider/QueueProviderInterface.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Provider/QueueProviderInterface.php b/src/Provider/QueueProviderInterface.php index 2e67a2f1..d833a84b 100644 --- a/src/Provider/QueueProviderInterface.php +++ b/src/Provider/QueueProviderInterface.php @@ -15,7 +15,7 @@ interface QueueProviderInterface /** * Find a queue by channel name and returns it. * - * @param string|BackedEnum $channel Channel name. + * @param BackedEnum|string $channel Channel name. * * @throws InvalidQueueConfigException If the queue configuration is invalid. * @throws ChannelNotFoundException If the channel is not found. @@ -27,7 +27,7 @@ public function get(string|BackedEnum $channel): QueueInterface; /** * Check if a queue with the specified channel name exists. * - * @param string|BackedEnum $channel Channel name. + * @param BackedEnum|string $channel Channel name. * * @return bool Whether the queue exists. */ From ef3e7a6d4fb23c70e5e1286e1dd8a1a15cdc7f22 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 12 Dec 2024 22:40:49 +0300 Subject: [PATCH 5/6] improve --- tests/App/FakeAdapter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/App/FakeAdapter.php b/tests/App/FakeAdapter.php index a8933689..237fef6d 100644 --- a/tests/App/FakeAdapter.php +++ b/tests/App/FakeAdapter.php @@ -6,6 +6,7 @@ use BackedEnum; use Yiisoft\Queue\Adapter\AdapterInterface; +use Yiisoft\Queue\ChannelNormalizer; use Yiisoft\Queue\Enum\JobStatus; use Yiisoft\Queue\Message\MessageInterface; @@ -40,7 +41,7 @@ public function withChannel(string|BackedEnum $channel): AdapterInterface { $instance = clone $this; $instance->pushMessages = []; - $instance->channel = $channel instanceof BackedEnum ? (string) $channel->value : $channel; + $instance->channel = ChannelNormalizer::normalize($channel); return $instance; } From 3c5267d7232d87374f17433f9e9d27fd1c97decf Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Mon, 16 Dec 2024 22:57:43 +0300 Subject: [PATCH 6/6] bump `yiisoft/definitions` version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9812ea48..3a570e00 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "psr/container": "^1.0|^2.0", "psr/log": "^2.0|^3.0", "symfony/console": "^5.4|^6.0", - "yiisoft/definitions": "^1.0|^2.0|^3.0", + "yiisoft/definitions": "^3.3.1", "yiisoft/factory": "^1.3", "yiisoft/friendly-exception": "^1.0", "yiisoft/injector": "^1.0"