Skip to content

Commit

Permalink
Move DEFAULT_CHANNEL_NAME to QueueInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Nov 11, 2024
1 parent 03b742d commit 00ee57d
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -24,7 +25,7 @@
'yiisoft/queue' => [
'handlers' => [],
'channels' => [
Queue::DEFAULT_CHANNEL_NAME => AdapterInterface::class,
QueueInterface::DEFAULT_CHANNEL_NAME => AdapterInterface::class,
],
'middlewares-push' => [],
'middlewares-consume' => [],
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/SynchronousAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
3 changes: 2 additions & 1 deletion src/Command/ListenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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,
);
}

Expand Down
5 changes: 1 addition & 4 deletions src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
*/
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/QueueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

interface QueueInterface
{
/** @psalm-suppress MissingClassConstType */
public const DEFAULT_CHANNEL_NAME = 'yii-queue';

/**
* Pushes a message into the queue.
*
Expand Down
2 changes: 1 addition & 1 deletion src/StubQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/StubQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand All @@ -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());
}
}
3 changes: 2 additions & 1 deletion tests/Unit/SynchronousAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 00ee57d

Please sign in to comment.