diff --git a/src/Adapter.php b/src/Adapter.php index 589f017..772f675 100644 --- a/src/Adapter.php +++ b/src/Adapter.php @@ -10,7 +10,9 @@ use Yiisoft\Queue\AMQP\Exception\NotImplementedException; use Yiisoft\Queue\Cli\LoopInterface; use Yiisoft\Queue\Enum\JobStatus; +use Yiisoft\Queue\Message\IdEnvelope; use Yiisoft\Queue\Message\MessageInterface; +use Yiisoft\Queue\Message\MessageSerializerInterface; final class Adapter implements AdapterInterface { @@ -23,33 +25,34 @@ public function __construct( public function withChannel(string $channel): self { - $instance = clone $this; - $instance->queueProvider = $this->queueProvider->withChannelName($channel); + $new = clone $this; + $new->queueProvider = $this->queueProvider->withChannelName($channel); - return $instance; + return $new; } /** - * @param callable(MessageInterface): bool $handlerCallback + * @param callable(MessageInterface): bool $handlerCallback */ public function runExisting(callable $handlerCallback): void { $channel = $this->queueProvider->getChannel(); - (new ExistingMessagesConsumer($channel, $this->queueProvider - ->getQueueSettings() - ->getName(), $this->serializer)) - ->consume($handlerCallback); + $queueName = $this->queueProvider->getQueueSettings()->getName(); + $consumer = new ExistingMessagesConsumer( + $channel, + $queueName, + $this->serializer + ); + + $consumer->consume($handlerCallback); } - /** - * @return never - */ - public function status(string $id): JobStatus + public function status(string|int $id): JobStatus { throw new NotImplementedException('Status check is not supported by the adapter ' . self::class . '.'); } - public function push(MessageInterface $message): void + public function push(MessageInterface $message): MessageInterface { $payload = $this->serializer->serialize($message); $amqpMessage = new AMQPMessage( @@ -57,30 +60,28 @@ public function push(MessageInterface $message): void array_merge(['message_id' => uniqid(more_entropy: true)], $this->queueProvider->getMessageProperties()) ); $exchangeSettings = $this->queueProvider->getExchangeSettings(); - $this->queueProvider - ->getChannel() - ->basic_publish( - $amqpMessage, - $exchangeSettings?->getName() ?? '', - $exchangeSettings ? '' : $this->queueProvider - ->getQueueSettings() - ->getName() - ); + $channel = $this->queueProvider->getChannel(); + $channel->basic_publish( + $amqpMessage, + $exchangeSettings?->getName() ?? '', + $exchangeSettings ? '' : $this->queueProvider + ->getQueueSettings() + ->getName() + ); /** @var string $messageId */ $messageId = $amqpMessage->get('message_id'); - $message->setId($messageId); + + return new IdEnvelope($message, $messageId); } public function subscribe(callable $handlerCallback): void { $channel = $this->queueProvider->getChannel(); + $queueName = $this->queueProvider->getQueueSettings()->getName(); + $channel->basic_consume( - $this->queueProvider - ->getQueueSettings() - ->getName(), - $this->queueProvider - ->getQueueSettings() - ->getName(), + $queueName, + $queueName, false, false, false, diff --git a/src/Exception/NoKeyInPayloadException.php b/src/Exception/NoKeyInPayloadException.php deleted file mode 100644 index 79ec038..0000000 --- a/src/Exception/NoKeyInPayloadException.php +++ /dev/null @@ -1,54 +0,0 @@ -expectedKey . '" in payload'; - } - - /** - * @return string - * - * @infection-ignore-all - */ - public function getSolution(): ?string - { - return sprintf( - "We have successfully unserialized a message, but there was no expected key \"%s\". - There are the following keys in the message: %s. - You might want to change message's structure, or make your own implementation of %s, - which won't rely on this key in the message.", - $this->expectedKey, - implode(', ', array_keys($this->payload)), - MessageSerializerInterface::class - ); - } -} diff --git a/src/ExistingMessagesConsumer.php b/src/ExistingMessagesConsumer.php index 4e030eb..f01f97a 100644 --- a/src/ExistingMessagesConsumer.php +++ b/src/ExistingMessagesConsumer.php @@ -8,6 +8,7 @@ use PhpAmqpLib\Message\AMQPMessage; use Throwable; use Yiisoft\Queue\Message\MessageInterface; +use Yiisoft\Queue\Message\MessageSerializerInterface; /** * @internal diff --git a/src/MessageSerializer.php b/src/MessageSerializer.php deleted file mode 100644 index 9afc07e..0000000 --- a/src/MessageSerializer.php +++ /dev/null @@ -1,64 +0,0 @@ - $message->getId(), - 'name' => $message->getHandlerName(), - 'data' => $message->getData(), - 'meta' => $message->getMetadata(), - ]; - - return json_encode($payload, JSON_THROW_ON_ERROR); - } - - /** - * @throws JsonException - * @throws NoKeyInPayloadException - * @throws InvalidArgumentException - */ - public function unserialize(string $value): Message - { - $payload = json_decode($value, true, 512, JSON_THROW_ON_ERROR); - if (!is_array($payload)) { - throw new InvalidArgumentException('Payload must be array. Got ' . get_debug_type($payload) . '.'); - } - - $name = $payload['name'] ?? null; - if (!is_string($name)) { - throw new NoKeyInPayloadException('name', $payload); - } - - $id = $payload['id'] ?? null; - if ($id !== null && !is_string($id)) { - throw new NoKeyInPayloadException('id', $payload); - } - - $meta = $payload['meta'] ?? []; - if (!is_array($meta)) { - throw new NoKeyInPayloadException('meta', $payload); - } - - return new Message( - $name, - $payload['data'] ?? null, - $meta, - $id, - ); - } -} diff --git a/src/MessageSerializerInterface.php b/src/MessageSerializerInterface.php deleted file mode 100644 index 4d84521..0000000 --- a/src/MessageSerializerInterface.php +++ /dev/null @@ -1,14 +0,0 @@ -getAdapter(); if (!$adapter instanceof Adapter) { - $type = get_debug_type($adapter); - $class = Adapter::class; throw new InvalidArgumentException( - "This middleware works only with the $class. $type given." + sprintf( + 'This middleware works only with the %s. %s given.', + Adapter::class, + get_debug_type($adapter) + ) ); } $queueProvider = $adapter->getQueueProvider(); - $exchangeSettings = $this->getExchangeSettings($queueProvider->getExchangeSettings()); - $queueSettings = $this->getQueueSettings($queueProvider->getQueueSettings(), $queueProvider->getExchangeSettings()); + $originalExchangeSettings = $queueProvider->getExchangeSettings(); + $delayedExchangeSettings = $this->getExchangeSettings($originalExchangeSettings); + $queueSettings = $this->getQueueSettings( + $queueProvider->getQueueSettings(), + $originalExchangeSettings + ); + $adapter = $adapter->withQueueProvider( $queueProvider ->withMessageProperties($this->getMessageProperties($queueProvider)) - ->withExchangeSettings($exchangeSettings) + ->withExchangeSettings($delayedExchangeSettings) ->withQueueSettings($queueSettings) ); @@ -104,7 +111,7 @@ private function getExchangeSettings(?ExchangeSettingsInterface $exchangeSetting /** @noinspection NullPointerExceptionInspection */ return $exchangeSettings ?->withName("{$exchangeSettings->getName()}.dlx") - ->withAutoDelete(true) + ->withAutoDelete(false) ->withType(AMQPExchangeType::TOPIC); } } diff --git a/src/QueueProvider.php b/src/QueueProvider.php index 54bf096..ae50b8b 100644 --- a/src/QueueProvider.php +++ b/src/QueueProvider.php @@ -31,6 +31,7 @@ public function __construct( public function __destruct() { $this->channel?->close(); + //unset($this->channel); } public function getChannel(): AMQPChannel diff --git a/src/Settings/Exchange.php b/src/Settings/Exchange.php index 53e54d8..25935de 100644 --- a/src/Settings/Exchange.php +++ b/src/Settings/Exchange.php @@ -14,7 +14,7 @@ public function __construct( private string $type = AMQPExchangeType::DIRECT, private bool $passive = false, private bool $durable = false, - private bool $autoDelete = true, + private bool $autoDelete = false, private bool $internal = false, private bool $nowait = false, private AMQPTable|array $arguments = [], diff --git a/src/Settings/Queue.php b/src/Settings/Queue.php index 69cb206..6df4bb8 100644 --- a/src/Settings/Queue.php +++ b/src/Settings/Queue.php @@ -14,7 +14,7 @@ public function __construct( private bool $passive = false, private bool $durable = false, private bool $exclusive = false, - private bool $autoDelete = true, + private bool $autoDelete = false, private bool $nowait = false, private AMQPTable|array $arguments = [], private ?int $ticket = null diff --git a/tests/Integration/DelayMiddlewareTest.php b/tests/Integration/DelayMiddlewareTest.php index 2d4003e..45a1209 100644 --- a/tests/Integration/DelayMiddlewareTest.php +++ b/tests/Integration/DelayMiddlewareTest.php @@ -9,7 +9,7 @@ use Psr\Log\LoggerInterface; use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\AMQP\Adapter; -use Yiisoft\Queue\AMQP\MessageSerializer; + use Yiisoft\Queue\AMQP\Middleware\DelayMiddleware; use Yiisoft\Queue\AMQP\QueueProvider; use Yiisoft\Queue\AMQP\Settings\Queue as QueueSettings; @@ -18,6 +18,7 @@ use Yiisoft\Queue\AMQP\Tests\Support\SimpleMessageHandler; use Yiisoft\Queue\Cli\LoopInterface; use Yiisoft\Queue\Cli\SignalLoop; +use Yiisoft\Queue\Message\JsonMessageSerializer; use Yiisoft\Queue\Message\Message; use Yiisoft\Queue\Middleware\CallableFactory; use Yiisoft\Queue\Middleware\Push\MiddlewareFactoryPush; @@ -44,7 +45,7 @@ public function testMainFlow(): void $this->createConnection(), new QueueSettings(), ), - new MessageSerializer(), + new JsonMessageSerializer(), new SignalLoop(), ); $queue = $this->makeQueue($adapter); @@ -75,7 +76,7 @@ public function testMainFlowWithFakeAdapter(): void $this->createConnection(), new QueueSettings(), ), - new MessageSerializer(), + new JsonMessageSerializer(), new SignalLoop(), ); $queue = $this->makeQueue($adapter); @@ -83,7 +84,7 @@ public function testMainFlowWithFakeAdapter(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("This middleware works only with the $adapterClass. $fakeAdapterClass given."); $queue->push( - new Message('simple', 'test-delay-middleware-main'), + new Message(SimpleMessageHandler::class, 'test-delay-middleware-main'), new DelayMiddleware(3), ); } diff --git a/tests/Support/FakeAdapter.php b/tests/Support/FakeAdapter.php index ddbbe15..cf8a7c9 100644 --- a/tests/Support/FakeAdapter.php +++ b/tests/Support/FakeAdapter.php @@ -5,11 +5,11 @@ namespace Yiisoft\Queue\AMQP\Tests\Support; use Yiisoft\Queue\Adapter\AdapterInterface; -use Yiisoft\Queue\AMQP\MessageSerializerInterface; use Yiisoft\Queue\AMQP\QueueProviderInterface; use Yiisoft\Queue\Cli\LoopInterface; use Yiisoft\Queue\Enum\JobStatus; use Yiisoft\Queue\Message\MessageInterface; +use Yiisoft\Queue\Message\MessageSerializerInterface; final class FakeAdapter implements AdapterInterface { @@ -25,12 +25,12 @@ public function runExisting(callable $handlerCallback): void // TODO: Implement runExisting() method. } - public function status(string $id): JobStatus + public function status(string|int $id): JobStatus { // TODO: Implement status() method. } - public function push(MessageInterface $message): void + public function push(MessageInterface $message): MessageInterface { // TODO: Implement push() method. } diff --git a/tests/Support/FileHelper.php b/tests/Support/FileHelper.php index beff8b2..d1674a2 100644 --- a/tests/Support/FileHelper.php +++ b/tests/Support/FileHelper.php @@ -14,8 +14,15 @@ final class FileHelper */ public function put(string $fileName, int|string $data): void { - if (file_put_contents("{$this->getRuntimeDir()}/$fileName", $data) === false) { - throw new RuntimeException("Runtime dir {$this->getRuntimeDir()} or file $fileName are not writable."); + $path = $this->getRuntimeDir() . DIRECTORY_SEPARATOR . $fileName; + if (file_put_contents($path, $data) === false) { + throw new RuntimeException( + sprintf( + 'Runtime dir %"s" or file "%s" are not writable.', + $this->getRuntimeDir(), + $fileName + ) + ); } } @@ -28,7 +35,12 @@ public function get(string $filename): ?string $result = file_get_contents($path); if ($result === false) { - throw new RuntimeException("File '$path' exists but is not readable."); + throw new RuntimeException( + sprintf( + 'File "%s" exists but is not readable.', + $path + ) + ); } return $result; diff --git a/tests/Support/MainTestCase.php b/tests/Support/MainTestCase.php index 66a9f16..030f1ae 100644 --- a/tests/Support/MainTestCase.php +++ b/tests/Support/MainTestCase.php @@ -15,10 +15,10 @@ abstract class MainTestCase extends TestCase protected function createConnection(): AMQPStreamConnection { return new AMQPStreamConnection( - getenv('RABBITMQ_HOST'), - getenv('RABBITMQ_PORT'), - getenv('RABBITMQ_USER'), - getenv('RABBITMQ_PASSWORD') + getenv('RABBITMQ_HOST') ?: '127.0.0.1', + getenv('RABBITMQ_PORT') ?: 5672, + getenv('RABBITMQ_USER') ?: 'guest', + getenv('RABBITMQ_PASSWORD') ?: 'guest', ); } diff --git a/tests/Unit/ExchangeSettingsTest.php b/tests/Unit/ExchangeSettingsTest.php index 5d16634..879dd19 100644 --- a/tests/Unit/ExchangeSettingsTest.php +++ b/tests/Unit/ExchangeSettingsTest.php @@ -7,10 +7,11 @@ use PhpAmqpLib\Exchange\AMQPExchangeType; use PhpAmqpLib\Wire\AMQPTable; use Yiisoft\Queue\AMQP\Adapter; -use Yiisoft\Queue\AMQP\MessageSerializer; + use Yiisoft\Queue\AMQP\QueueProvider; use Yiisoft\Queue\AMQP\Settings\Exchange as ExchangeSettings; use Yiisoft\Queue\AMQP\Settings\Queue as QueueSettings; +use Yiisoft\Queue\Message\JsonMessageSerializer; final class ExchangeSettingsTest extends UnitTestCase { @@ -38,7 +39,7 @@ public function testCommonSettings(): void ]) ) ), - new MessageSerializer(), + new JsonMessageSerializer(), $this->getLoop(), ); $exchangeSettings = $adapter->getQueueProvider()->getExchangeSettings(); diff --git a/tests/Unit/FriendlyExceptionTest.php b/tests/Unit/FriendlyExceptionTest.php deleted file mode 100644 index 6e14fab..0000000 --- a/tests/Unit/FriendlyExceptionTest.php +++ /dev/null @@ -1,29 +0,0 @@ -getName()); - $this->assertMatchesRegularExpression('/test/', $exception->getSolution()); - } - - public function testExchangeDeclaredException(): void - { - $exception = new ExchangeDeclaredException(); - - self::assertSame('Exchange is declared', $exception->getName()); - } -} diff --git a/tests/Unit/MessageSerializerTest.php b/tests/Unit/MessageSerializerTest.php deleted file mode 100644 index 8a2c9a0..0000000 --- a/tests/Unit/MessageSerializerTest.php +++ /dev/null @@ -1,134 +0,0 @@ -createConnection() - ->channel(); - $channel->queue_declare($queue); - $channel->exchange_declare($exchange, AMQPExchangeType::DIRECT); - $channel->queue_bind($queue, $exchange); - $channel->basic_publish($message, $exchange); - } - - /** - * @throws Exception - */ - private function getCustomAdapter(string $queueExchangeName): Adapter - { - $queueProvider = new QueueProvider( - $this->createConnection(), - $this->getQueueSettings(), - ); - return new Adapter( - $queueProvider - ->withQueueSettings(new QueueSettings($queueExchangeName)) - ->withExchangeSettings(new ExchangeSettings($queueExchangeName)), - new MessageSerializer(), - $this->getLoop(), - ); - } - - public function testNoKeyInPayloadExceptionName(): void - { - $queueExchangeName = 'yii-test-no-key-in-payload-exception-name'; - $this->publishWithAMQPLib( - $queueExchangeName, - $queueExchangeName, - new AMQPMessage( - json_encode(['test'], JSON_THROW_ON_ERROR), - ['content_type' => 'text/json', 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT] - ) - ); - - $this->expectException(NoKeyInPayloadException::class); - $this - ->getQueue() - ->withAdapter($this->getCustomAdapter($queueExchangeName)) - ->run(); - } - - public function testNoKeyInPayloadExceptionId(): void - { - $queueExchangeName = 'yii-test-no-key-in-payload-exception-id'; - $this->publishWithAMQPLib( - $queueExchangeName, - $queueExchangeName, - new AMQPMessage( - json_encode(['name' => 'ext-simple', 'id' => 1], JSON_THROW_ON_ERROR), - ['content_type' => 'text/json', 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT] - ) - ); - - $this->expectException(NoKeyInPayloadException::class); - $this->expectExceptionMessage("No expected key 'id' in payload. Payload's keys list: name, id."); - $this - ->getQueue() - ->withAdapter($this->getCustomAdapter($queueExchangeName)) - ->run(); - } - - public function testNoKeyInPayloadExceptionMeta(): void - { - $queueExchangeName = 'yii-test-no-key-in-payload-exception-meta'; - $this->publishWithAMQPLib( - $queueExchangeName, - $queueExchangeName, - new AMQPMessage( - json_encode(['name' => 'ext-simple', 'meta' => ''], JSON_THROW_ON_ERROR), - ['content_type' => 'text/json', 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT] - ) - ); - - $this->expectException(NoKeyInPayloadException::class); - $this->expectExceptionMessage("No expected key 'meta' in payload. Payload's keys list: name, meta."); - $this - ->getQueue() - ->withAdapter($this->getCustomAdapter($queueExchangeName)) - ->run(); - } - - public function testInvalidArgumentException(): void - { - $queueExchangeName = 'yii-test-invalid-argument-exception'; - $this->publishWithAMQPLib( - $queueExchangeName, - $queueExchangeName, - new AMQPMessage( - json_encode('test', JSON_THROW_ON_ERROR), - ['content_type' => 'text/json', 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT] - ) - ); - - $this->expectException(InvalidArgumentException::class); - $this - ->getQueue() - ->withAdapter($this->getCustomAdapter($queueExchangeName)) - ->run(); - } -} diff --git a/tests/Unit/QueueProviderTest.php b/tests/Unit/QueueProviderTest.php index 897f257..da9584c 100644 --- a/tests/Unit/QueueProviderTest.php +++ b/tests/Unit/QueueProviderTest.php @@ -6,13 +6,14 @@ use Yiisoft\Queue\AMQP\Adapter; use Yiisoft\Queue\AMQP\Exception\ExchangeDeclaredException; -use Yiisoft\Queue\AMQP\MessageSerializer; + use Yiisoft\Queue\AMQP\QueueProvider; use Yiisoft\Queue\AMQP\Settings\Exchange as ExchangeSettings; use Yiisoft\Queue\AMQP\Settings\ExchangeSettingsInterface; use Yiisoft\Queue\AMQP\Settings\Queue as QueueSettings; use Yiisoft\Queue\AMQP\Settings\QueueSettingsInterface; use Yiisoft\Queue\AMQP\Tests\Support\FileHelper; +use Yiisoft\Queue\Message\JsonMessageSerializer; use Yiisoft\Queue\Message\Message; final class QueueProviderTest extends UnitTestCase @@ -34,7 +35,7 @@ public function testWithQueueAndExchangeSettings(): void ->withExchangeSettings( new ExchangeSettings($this->exchangeName) ), - new MessageSerializer(), + new JsonMessageSerializer(), $this->getLoop(), ); @@ -81,7 +82,7 @@ public function testWithChannelNameExchangeDeclaredException(): void new ExchangeSettings('yii-queue-test-with-channel-name') ) ->withChannelName('yii-queue-test-channel-name'), - new MessageSerializer(), + new JsonMessageSerializer(), $this->getLoop(), ); } diff --git a/tests/Unit/QueueSettingsTest.php b/tests/Unit/QueueSettingsTest.php index 446e6db..ed61cf3 100644 --- a/tests/Unit/QueueSettingsTest.php +++ b/tests/Unit/QueueSettingsTest.php @@ -7,10 +7,11 @@ use PhpAmqpLib\Exception\AMQPProtocolChannelException; use PhpAmqpLib\Wire\AMQPTable; use Yiisoft\Queue\AMQP\Adapter; -use Yiisoft\Queue\AMQP\MessageSerializer; + use Yiisoft\Queue\AMQP\QueueProvider; use Yiisoft\Queue\AMQP\Settings\Exchange as ExchangeSettings; use Yiisoft\Queue\AMQP\Settings\Queue as QueueSettings; +use Yiisoft\Queue\Message\JsonMessageSerializer; use Yiisoft\Queue\Message\Message; final class QueueSettingsTest extends UnitTestCase @@ -40,7 +41,7 @@ public function testCommonSettings(): void ->withExchangeSettings( new ExchangeSettings('yii-queue-test-queue-common-settings') ), - new MessageSerializer(), + new JsonMessageSerializer(), $this->getLoop(), ); @@ -49,7 +50,7 @@ public function testCommonSettings(): void self::assertTrue($queueSettings->isDurable()); self::assertTrue($queueSettings->isPassive()); self::assertTrue($queueSettings->isExclusive()); - self::assertTrue($queueSettings->isAutoDeletable()); + self::assertFalse($queueSettings->isAutoDeletable()); self::assertTrue($queueSettings->hasNowait()); self::assertNull($queueSettings->getTicket()); @@ -85,7 +86,7 @@ public function testArgumentsXExpires(): void ->withExchangeSettings( new ExchangeSettings('yii-queue-test-queue-settings-arg') ), - new MessageSerializer(), + new JsonMessageSerializer(), $this->getLoop(), ); diff --git a/tests/Unit/QueueTest.php b/tests/Unit/QueueTest.php index 84f1619..c24a134 100644 --- a/tests/Unit/QueueTest.php +++ b/tests/Unit/QueueTest.php @@ -8,8 +8,6 @@ use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\AMQP\Adapter; use Yiisoft\Queue\AMQP\Exception\NotImplementedException; -use Yiisoft\Queue\AMQP\MessageSerializer; -use Yiisoft\Queue\AMQP\MessageSerializerInterface; use Yiisoft\Queue\AMQP\QueueProvider; use Yiisoft\Queue\AMQP\QueueProviderInterface; use Yiisoft\Queue\AMQP\Settings\Exchange as ExchangeSettings; @@ -17,7 +15,10 @@ use Yiisoft\Queue\AMQP\Tests\Support\FileHelper; use Yiisoft\Queue\Cli\LoopInterface; use Yiisoft\Queue\Exception\JobFailureException; +use Yiisoft\Queue\Message\IdEnvelope; +use Yiisoft\Queue\Message\JsonMessageSerializer; use Yiisoft\Queue\Message\Message; +use Yiisoft\Queue\Message\MessageSerializerInterface; use Yiisoft\Queue\Queue; final class QueueTest extends UnitTestCase @@ -34,10 +35,11 @@ public function testStatus(): void $queue = $this->getDefaultQueue($adapter); - $message = new Message('ext-simple', null); - $queue->push( - $message, + $message = new IdEnvelope( + new Message('ext-simple', null), + 'test-id', ); + $queue->push($message); $this->expectException(NotImplementedException::class); $this->expectExceptionMessage("Status check is not supported by the adapter $adapterClass."); @@ -84,7 +86,7 @@ public function testListenWithException(): void $queueProvider ->withQueueSettings(new QueueSettings($this->queueName)) ->withExchangeSettings(new ExchangeSettings($this->exchangeName)), - new MessageSerializer(), + new JsonMessageSerializer(), $this->getLoop(), ); $queue = $this->getDefaultQueue($adapter); @@ -110,9 +112,8 @@ public function testListen(): void $this->getQueueSettings(), ); $adapter = new Adapter( - $queueProvider - ->withChannelName('yii-queue'), - new MessageSerializer(), + $queueProvider->withChannelName('yii-queue'), + new JsonMessageSerializer(), $mockLoop, ); $queue = $this->getDefaultQueue($adapter); diff --git a/tests/Unit/UnitTestCase.php b/tests/Unit/UnitTestCase.php index 2f119c5..e617ab6 100644 --- a/tests/Unit/UnitTestCase.php +++ b/tests/Unit/UnitTestCase.php @@ -10,7 +10,7 @@ use Yiisoft\Injector\Injector; use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\AMQP\Adapter; -use Yiisoft\Queue\AMQP\MessageSerializer; + use Yiisoft\Queue\AMQP\QueueProvider; use Yiisoft\Queue\AMQP\Settings\Queue as QueueSettings; use Yiisoft\Queue\AMQP\Tests\Support\ExtendedSimpleMessageHandler; @@ -18,6 +18,7 @@ use Yiisoft\Queue\AMQP\Tests\Support\MainTestCase; use Yiisoft\Queue\Cli\LoopInterface; use Yiisoft\Queue\Cli\SignalLoop; +use Yiisoft\Queue\Message\JsonMessageSerializer; use Yiisoft\Queue\Message\MessageInterface; use Yiisoft\Queue\Middleware\CallableFactory; use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareDispatcher; @@ -134,7 +135,7 @@ protected function getAdapter(): AdapterInterface { return $this->adapter ??= new Adapter( $this->getQueueProvider(), - new MessageSerializer(), + new JsonMessageSerializer(), $this->getLoop(), ); } diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 18aebec..3a56465 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -44,9 +44,12 @@ services: PHP_VERSION: '8.2' rabbitmq: - image: rabbitmq:3-alpine + image: rabbitmq:3-management healthcheck: test: rabbitmq-diagnostics check_port_connectivity interval: 3s timeout: 5s retries: 3 + ports: + - 5672:5672 + - 5673:15672 diff --git a/tests/yii b/tests/yii index 7ae7c3e..48d48f9 100755 --- a/tests/yii +++ b/tests/yii @@ -4,10 +4,11 @@ use PhpAmqpLib\Connection\AMQPStreamConnection; use Psr\Log\NullLogger; use Yiisoft\Injector\Injector; +use Yiisoft\Queue\Message\JsonMessageSerializer; use Yiisoft\Test\Support\Container\SimpleContainer; use Yiisoft\Yii\Console\Application; use Yiisoft\Queue\AMQP\Adapter; -use Yiisoft\Queue\AMQP\MessageSerializer; + use Yiisoft\Queue\AMQP\QueueProvider; use Yiisoft\Queue\AMQP\Settings\Queue as QueueSettings; use Yiisoft\Queue\AMQP\Tests\Support\FileHelper; @@ -53,7 +54,7 @@ $adapter = new Adapter( ), new QueueSettings(), ), - new MessageSerializer(), + new JsonMessageSerializer(), $loop, ); $queue = new Queue(