From e8fd270bffebfc8f49d8f763236b8c4fe6cebf55 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Mon, 11 May 2026 16:45:26 +0200 Subject: [PATCH] Remove dead code --- src/Adapter.php | 29 ------------ src/Exception/NotImplementedException.php | 11 ----- src/QueueProvider.php | 16 +------ tests/Support/FakeAdapter.php | 54 ----------------------- tests/Unit/ExchangeSettingsTest.php | 39 +++++----------- tests/Unit/QueueProviderTest.php | 4 +- tests/Unit/QueueSettingsTest.php | 38 +++++----------- tests/Unit/QueueTest.php | 15 +------ 8 files changed, 26 insertions(+), 180 deletions(-) delete mode 100644 src/Exception/NotImplementedException.php delete mode 100644 tests/Support/FakeAdapter.php diff --git a/src/Adapter.php b/src/Adapter.php index fb1a653..27e6015 100644 --- a/src/Adapter.php +++ b/src/Adapter.php @@ -27,17 +27,6 @@ public function __construct( ) { } - public function withChannel(BackedEnum|string $channel): self - { - $instance = clone $this; - - $channelName = is_string($channel) ? $channel : (string) $channel->value; - $instance->queueProvider = $this->queueProvider->withChannelName($channelName); - $instance->amqpMessage = null; - - return $instance; - } - /** * @param callable(MessageInterface): bool $handlerCallback */ @@ -165,22 +154,4 @@ function (AMQPMessage $amqpMessage) use ($handlerCallback, $channel): void { $channel->wait(); } } - - public function getQueueProvider(): QueueProviderInterface - { - return $this->queueProvider; - } - - public function withQueueProvider(QueueProviderInterface $queueProvider): self - { - $new = clone $this; - $new->queueProvider = $queueProvider; - - return $new; - } - - public function getChannel(): string - { - return $this->queueProvider->getQueueSettings()->getName(); - } } diff --git a/src/Exception/NotImplementedException.php b/src/Exception/NotImplementedException.php deleted file mode 100644 index 3e624e0..0000000 --- a/src/Exception/NotImplementedException.php +++ /dev/null @@ -1,11 +0,0 @@ -channelId = $this->connection->get_free_channel_id(); - $channel = $this->connection->channel($this->getChannelId()); + $channel = $this->connection->channel($this->channelId); $channel->queue_declare(...$this->queueSettings->getPositionalSettings()); if ($this->exchangeSettings !== null) { @@ -87,10 +87,7 @@ public function withQueueName(string $queue): self } $instance = clone $this; - $instance->queueSettings = $instance->queueSettings->withName($channel); - if ($this->channelId !== null) { - $instance->channelId = null; - } + $instance->queueSettings = $instance->queueSettings->withName($queue); return $instance; } @@ -135,13 +132,4 @@ public function channelClose(): void $this->channelId = null; } } - - private function getChannelId(): int - { - if ($this->channelId === null) { - $this->channelId = $this->connection->get_free_channel_id(); - } - - return $this->channelId; - } } diff --git a/tests/Support/FakeAdapter.php b/tests/Support/FakeAdapter.php deleted file mode 100644 index 7868a59..0000000 --- a/tests/Support/FakeAdapter.php +++ /dev/null @@ -1,54 +0,0 @@ -createConnection(), - $this->getQueueSettings(), + $exchangeSettings = new ExchangeSettings( + exchangeName: 'yii-queue-test-common-settings', + passive: true, + durable: true, + autoDelete: false, + internal: true, + nowait: true, + arguments: new AMQPTable([ + 'alternate-exchange' => 'yii-queue-test-common-settings-alt', + ]) ); - $adapter = new Adapter( - $queueProvider - ->withQueueSettings( - new QueueSettings('yii-queue-test-common-settings') - ) - ->withExchangeSettings( - new ExchangeSettings( - exchangeName: 'yii-queue-test-common-settings', - passive: true, - durable: true, - autoDelete: false, - internal: true, - nowait: true, - arguments: new AMQPTable([ - 'alternate-exchange' => 'yii-queue-test-common-settings-alt', - ]) - ) - ), - new JsonMessageSerializer(), - $this->getLoop(), - ); - $exchangeSettings = $adapter->getQueueProvider()->getExchangeSettings(); self::assertTrue($exchangeSettings->isDurable()); self::assertTrue($exchangeSettings->isInternal()); diff --git a/tests/Unit/QueueProviderTest.php b/tests/Unit/QueueProviderTest.php index ebd4a1a..8c10ec7 100644 --- a/tests/Unit/QueueProviderTest.php +++ b/tests/Unit/QueueProviderTest.php @@ -64,7 +64,7 @@ public function testWithQueueAndExchangeSettings(): void self::assertEquals($messageBody['data']['payload']['time'], $result); } - public function testWithChannelNameExchangeDeclaredException(): void + public function testWithQueueNameExchangeDeclaredException(): void { $queueProvider = new QueueProvider( $this->createConnection(), @@ -80,7 +80,7 @@ public function testWithChannelNameExchangeDeclaredException(): void ->withExchangeSettings( new ExchangeSettings('yii-queue-test-with-channel-name') ) - ->withChannelName('yii-queue-test-channel-name'), + ->withQueueName('yii-queue-test-queue-name'), new JsonMessageSerializer(), $this->getLoop(), ); diff --git a/tests/Unit/QueueSettingsTest.php b/tests/Unit/QueueSettingsTest.php index 5c6b2ec..653d143 100644 --- a/tests/Unit/QueueSettingsTest.php +++ b/tests/Unit/QueueSettingsTest.php @@ -40,34 +40,18 @@ protected function setUp(): void public function testCommonSettings(): void { - $queueProvider = new QueueProvider( - $this->createConnection(), - $this->getQueueSettings(), + $queueSettings = new QueueSettings( + queueName: 'yii-queue-test-queue-common-settings', + passive: true, + durable: true, + exclusive: true, + nowait: true, + arguments: new AMQPTable([ + 'x-dead-letter-exchange' => 'yii-queue-test-queue-common-settings-dead-letter-exc', + 'x-message-ttl' => 15000, + 'x-expires' => 16000, + ]) ); - $adapter = new Adapter( - $queueProvider - ->withQueueSettings( - new QueueSettings( - queueName: 'yii-queue-test-queue-common-settings', - passive: true, - durable: true, - exclusive: true, - nowait: true, - arguments: new AMQPTable([ - 'x-dead-letter-exchange' => 'yii-queue-test-queue-common-settings-dead-letter-exc', - 'x-message-ttl' => 15000, - 'x-expires' => 16000, - ]) - ) - ) - ->withExchangeSettings( - new ExchangeSettings('yii-queue-test-queue-common-settings') - ), - new JsonMessageSerializer(), - $this->getLoop(), - ); - - $queueSettings = $adapter->getQueueProvider()->getQueueSettings(); self::assertTrue($queueSettings->isDurable()); self::assertTrue($queueSettings->isPassive()); diff --git a/tests/Unit/QueueTest.php b/tests/Unit/QueueTest.php index d1a6a63..1528381 100644 --- a/tests/Unit/QueueTest.php +++ b/tests/Unit/QueueTest.php @@ -107,7 +107,7 @@ public function testListen(): void ); $adapter = new Adapter( $queueProvider - ->withChannelName('yii-queue'), + ->withQueueName('yii-queue'), new JsonMessageSerializer(), $mockLoop, ); @@ -123,17 +123,4 @@ private function getDefaultQueue(AdapterInterface $adapter): Queue { return $this->makeQueue($adapter); } - - public function testImmutable(): void - { - $queueProvider = $this->createMock(QueueProviderInterface::class); - $adapter = new Adapter( - $queueProvider, - $this->createMock(MessageSerializerInterface::class), - $this->createMock(LoopInterface::class) - ); - - self::assertNotSame($adapter, $adapter->withChannel('test')); - self::assertNotSame($adapter, $adapter->withQueueProvider($queueProvider)); - } }