From 00ee57d0a8bff38fddb8a54b9c875078cd5a9bf0 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Mon, 11 Nov 2024 10:39:45 +0300 Subject: [PATCH] Move `DEFAULT_CHANNEL_NAME` to `QueueInterface` --- config/params.php | 3 ++- src/Adapter/SynchronousAdapter.php | 2 +- src/Command/ListenCommand.php | 3 ++- src/Queue.php | 5 +---- src/QueueInterface.php | 3 +++ src/StubQueue.php | 2 +- tests/Unit/StubQueueTest.php | 5 +++-- tests/Unit/SynchronousAdapterTest.php | 3 ++- 8 files changed, 15 insertions(+), 11 deletions(-) diff --git a/config/params.php b/config/params.php index 0d412dcf..0a8d5656 100644 --- a/config/params.php +++ b/config/params.php @@ -11,6 +11,7 @@ use Yiisoft\Queue\Debug\QueueWorkerInterfaceProxy; use Yiisoft\Queue\Provider\QueueProviderInterface; use Yiisoft\Queue\Queue; +use Yiisoft\Queue\QueueInterface; use Yiisoft\Queue\Worker\WorkerInterface; return [ @@ -24,7 +25,7 @@ 'yiisoft/queue' => [ 'handlers' => [], 'channels' => [ - Queue::DEFAULT_CHANNEL_NAME => AdapterInterface::class, + QueueInterface::DEFAULT_CHANNEL_NAME => AdapterInterface::class, ], 'middlewares-push' => [], 'middlewares-consume' => [], diff --git a/src/Adapter/SynchronousAdapter.php b/src/Adapter/SynchronousAdapter.php index 46dca1df..950fbc3e 100644 --- a/src/Adapter/SynchronousAdapter.php +++ b/src/Adapter/SynchronousAdapter.php @@ -20,7 +20,7 @@ final class SynchronousAdapter implements AdapterInterface public function __construct( private WorkerInterface $worker, private QueueInterface $queue, - private string $channel = Queue::DEFAULT_CHANNEL_NAME, + private string $channel = QueueInterface::DEFAULT_CHANNEL_NAME, ) { } diff --git a/src/Command/ListenCommand.php b/src/Command/ListenCommand.php index 752852e9..8a80a625 100644 --- a/src/Command/ListenCommand.php +++ b/src/Command/ListenCommand.php @@ -10,6 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Yiisoft\Queue\Provider\QueueProviderInterface; use Yiisoft\Queue\Queue; +use Yiisoft\Queue\QueueInterface; final class ListenCommand extends Command { @@ -28,7 +29,7 @@ public function configure(): void 'channel', InputArgument::OPTIONAL, 'Queue channel name to connect to', - Queue::DEFAULT_CHANNEL_NAME, + QueueInterface::DEFAULT_CHANNEL_NAME, ); } diff --git a/src/Queue.php b/src/Queue.php index be600317..4ba0d2e0 100644 --- a/src/Queue.php +++ b/src/Queue.php @@ -20,9 +20,6 @@ final class Queue implements QueueInterface { - /** @psalm-suppress MissingClassConstType */ - public const DEFAULT_CHANNEL_NAME = 'yii-queue'; - /** * @var array|array[]|callable[]|MiddlewarePushInterface[]|string[] */ @@ -35,7 +32,7 @@ public function __construct( private LoggerInterface $logger, private PushMiddlewareDispatcher $pushMiddlewareDispatcher, private ?AdapterInterface $adapter = null, - private string $channelName = self::DEFAULT_CHANNEL_NAME, + private string $channelName = QueueInterface::DEFAULT_CHANNEL_NAME, MiddlewarePushInterface|callable|array|string ...$middlewareDefinitions ) { $this->middlewareDefinitions = $middlewareDefinitions; diff --git a/src/QueueInterface.php b/src/QueueInterface.php index 80a5016b..2204a4b1 100644 --- a/src/QueueInterface.php +++ b/src/QueueInterface.php @@ -12,6 +12,9 @@ interface QueueInterface { + /** @psalm-suppress MissingClassConstType */ + public const DEFAULT_CHANNEL_NAME = 'yii-queue'; + /** * Pushes a message into the queue. * diff --git a/src/StubQueue.php b/src/StubQueue.php index 8f06e2da..343c4e93 100644 --- a/src/StubQueue.php +++ b/src/StubQueue.php @@ -15,7 +15,7 @@ final class StubQueue implements QueueInterface { public function __construct( - private string $channelName = Queue::DEFAULT_CHANNEL_NAME, + private string $channelName = QueueInterface::DEFAULT_CHANNEL_NAME, private ?AdapterInterface $adapter = null, ) { } diff --git a/tests/Unit/StubQueueTest.php b/tests/Unit/StubQueueTest.php index 12e49080..314f0915 100644 --- a/tests/Unit/StubQueueTest.php +++ b/tests/Unit/StubQueueTest.php @@ -8,6 +8,7 @@ use Yiisoft\Queue\Adapter\StubAdapter; use Yiisoft\Queue\Message\Message; use Yiisoft\Queue\Queue; +use Yiisoft\Queue\QueueInterface; use Yiisoft\Queue\StubQueue; final class StubQueueTest extends TestCase @@ -20,7 +21,7 @@ public function testBase(): void $this->assertSame($message, $queue->push($message)); $this->assertSame(0, $queue->run()); $this->assertTrue($queue->status('test')->isDone()); - $this->assertSame(Queue::DEFAULT_CHANNEL_NAME, $queue->getChannelName()); + $this->assertSame(QueueInterface::DEFAULT_CHANNEL_NAME, $queue->getChannelName()); $this->assertNull($queue->getAdapter()); $queue->listen(); } @@ -42,7 +43,7 @@ public function testWithChannelName(): void $queue = $sourceQueue->withChannelName('test'); $this->assertNotSame($queue, $sourceQueue); - $this->assertSame(Queue::DEFAULT_CHANNEL_NAME, $sourceQueue->getChannelName()); + $this->assertSame(QueueInterface::DEFAULT_CHANNEL_NAME, $sourceQueue->getChannelName()); $this->assertSame('test', $queue->getChannelName()); } } diff --git a/tests/Unit/SynchronousAdapterTest.php b/tests/Unit/SynchronousAdapterTest.php index 7c369ae7..fae31fe2 100644 --- a/tests/Unit/SynchronousAdapterTest.php +++ b/tests/Unit/SynchronousAdapterTest.php @@ -7,6 +7,7 @@ use Yiisoft\Queue\Enum\JobStatus; use Yiisoft\Queue\Message\Message; use Yiisoft\Queue\Queue; +use Yiisoft\Queue\QueueInterface; use Yiisoft\Queue\Tests\TestCase; use Yiisoft\Queue\Message\IdEnvelope; @@ -51,7 +52,7 @@ public function testIdSetting(): void public function testWithSameChannel(): void { $adapter = $this->getAdapter(); - self::assertEquals($adapter, $adapter->withChannel(Queue::DEFAULT_CHANNEL_NAME)); + self::assertEquals($adapter, $adapter->withChannel(QueueInterface::DEFAULT_CHANNEL_NAME)); } public function testWithAnotherChannel(): void