diff --git a/src/Adapter.php b/src/Adapter.php index 589f017..c33263c 100644 --- a/src/Adapter.php +++ b/src/Adapter.php @@ -10,6 +10,7 @@ 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; final class Adapter implements AdapterInterface @@ -23,33 +24,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 +59,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/MessageSerializer.php b/src/MessageSerializer.php index 9afc07e..e91de5a 100644 --- a/src/MessageSerializer.php +++ b/src/MessageSerializer.php @@ -7,6 +7,7 @@ use InvalidArgumentException; use JsonException; use Yiisoft\Queue\AMQP\Exception\NoKeyInPayloadException; +use Yiisoft\Queue\Message\IdEnvelope; use Yiisoft\Queue\Message\Message; use Yiisoft\Queue\Message\MessageInterface; @@ -18,7 +19,7 @@ class MessageSerializer implements MessageSerializerInterface public function serialize(MessageInterface $message): string { $payload = [ - 'id' => $message->getId(), + 'id' => $message->getMetadata()[IdEnvelope::MESSAGE_ID_KEY] ?? null, 'name' => $message->getHandlerName(), 'data' => $message->getData(), 'meta' => $message->getMetadata(), diff --git a/src/Middleware/DelayMiddleware.php b/src/Middleware/DelayMiddleware.php index c1eb0a7..defe258 100644 --- a/src/Middleware/DelayMiddleware.php +++ b/src/Middleware/DelayMiddleware.php @@ -43,20 +43,27 @@ public function processPush(PushRequest $request, MessageHandlerPushInterface $h { $adapter = $request->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) ); @@ -78,20 +85,17 @@ private function getMessageProperties(QueueProviderInterface $queueProvider): ar private function getQueueSettings( QueueSettingsInterface $queueSettings, - ?ExchangeSettingsInterface $exchangeSettings + ?ExchangeSettingsInterface $originalExchangeSettings ): QueueSettingsInterface { - $deliveryTime = time() + $this->delayInSeconds; - + $arguments = [ + 'x-dead-letter-exchange' => ['S', $originalExchangeSettings?->getName() ?? ''], + 'x-dead-routing-key' => ['S', $queueSettings->getName()], + 'x-expires' => ['I', $this->delayInSeconds * 1000 + 30_000], + 'x-message-ttl' => ['I', $this->delayInSeconds * 1000], + ]; return $queueSettings - ->withName("{$queueSettings->getName()}.dlx.$deliveryTime") - ->withAutoDeletable(true) - ->withArguments( - [ - 'x-dead-letter-exchange' => ['S', $exchangeSettings?->getName() ?? ''], - 'x-expires' => ['I', $this->delayInSeconds * 1000 + 30000], - 'x-message-ttl' => ['I', $this->delayInSeconds * 1000], - ] - ); + ->withName("{$queueSettings->getName()}.dlx") + ->withArguments($arguments); } /** @@ -104,7 +108,6 @@ private function getExchangeSettings(?ExchangeSettingsInterface $exchangeSetting /** @noinspection NullPointerExceptionInspection */ return $exchangeSettings ?->withName("{$exchangeSettings->getName()}.dlx") - ->withAutoDelete(true) ->withType(AMQPExchangeType::TOPIC); } } diff --git a/src/QueueProvider.php b/src/QueueProvider.php index 54bf096..2d64060 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..b8a5c9e 100644 --- a/tests/Integration/DelayMiddlewareTest.php +++ b/tests/Integration/DelayMiddlewareTest.php @@ -51,7 +51,7 @@ public function testMainFlow(): void $time = time(); $queue->push( - new Message('simple', 'test-delay-middleware-main'), + new Message(SimpleMessageHandler::class, 'test-delay-middleware-main'), new DelayMiddleware(3), ); @@ -96,9 +96,7 @@ private function makeQueue(AdapterInterface $adapter): Queue $this->createMock(LoggerInterface::class), new PushMiddlewareDispatcher( new MiddlewareFactoryPush( - new SimpleContainer([ - 'simple' => new SimpleMessageHandler(new FileHelper()), - ]), + new SimpleContainer([]), new CallableFactory($this->createMock(ContainerInterface::class)), ), ), diff --git a/tests/Integration/TestCase.php b/tests/Integration/TestCase.php index d1028a0..b93f384 100644 --- a/tests/Integration/TestCase.php +++ b/tests/Integration/TestCase.php @@ -40,7 +40,6 @@ protected function tearDown(): void protected function queueListen(?string $queue = null): void { - // TODO Fail test on subprocess error exit code $command = [PHP_BINARY, dirname(__DIR__) . '/yii', 'queue:listen']; if ($queue !== null) { $command[] = "--channel=$queue"; @@ -48,5 +47,14 @@ protected function queueListen(?string $queue = null): void $process = new Process($command); $this->processes[] = $process; $process->start(); + + if ($process->isTerminated()) { + throw new \RuntimeException( + sprintf( + "Failed to start queue:listen process: \n%s", + !empty($process->getErrorOutput()) ? $process->getErrorOutput() : $process->getOutput() + ) + ); + } } } diff --git a/tests/Support/ExceptionListener.php b/tests/Support/ExceptionListener.php new file mode 100644 index 0000000..921d064 --- /dev/null +++ b/tests/Support/ExceptionListener.php @@ -0,0 +1,19 @@ +getData(); + if (null !== $data) { + throw new PHPUnitException((string) $data['payload']['time']); + } + } +} diff --git a/tests/Support/ExtendedSimpleMessageHandler.php b/tests/Support/ExtendedSimpleMessageHandler.php index 2c5ad88..d2a8625 100644 --- a/tests/Support/ExtendedSimpleMessageHandler.php +++ b/tests/Support/ExtendedSimpleMessageHandler.php @@ -15,7 +15,7 @@ public function __construct(private FileHelper $fileHelper) { } - public function handle(MessageInterface $message): void + public function __invoke(MessageInterface $message): void { $data = $message->getData(); if (null !== $data) { diff --git a/tests/Support/FakeAdapter.php b/tests/Support/FakeAdapter.php index ddbbe15..3f0f7ee 100644 --- a/tests/Support/FakeAdapter.php +++ b/tests/Support/FakeAdapter.php @@ -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/Unit/MessageSerializerTest.php b/tests/Unit/MessageSerializerTest.php index 8a2c9a0..97b881d 100644 --- a/tests/Unit/MessageSerializerTest.php +++ b/tests/Unit/MessageSerializerTest.php @@ -14,6 +14,7 @@ use Yiisoft\Queue\AMQP\QueueProvider; use Yiisoft\Queue\AMQP\Settings\Exchange as ExchangeSettings; use Yiisoft\Queue\AMQP\Settings\Queue as QueueSettings; +use Yiisoft\Queue\AMQP\Tests\Support\ExtendedSimpleMessageHandler; /** * Testing message serialization options @@ -27,11 +28,10 @@ final class MessageSerializerTest extends UnitTestCase */ private function publishWithAMQPLib(string $queue, string $exchange, AMQPMessage $message): void { - $channel = $this - ->createConnection() - ->channel(); + $channel = $this->createConnection()->channel(); + $channel->queue_declare($queue); - $channel->exchange_declare($exchange, AMQPExchangeType::DIRECT); + $channel->exchange_declare($exchange, AMQPExchangeType::DIRECT, auto_delete: true); $channel->queue_bind($queue, $exchange); $channel->basic_publish($message, $exchange); } @@ -47,8 +47,8 @@ private function getCustomAdapter(string $queueExchangeName): Adapter ); return new Adapter( $queueProvider - ->withQueueSettings(new QueueSettings($queueExchangeName)) - ->withExchangeSettings(new ExchangeSettings($queueExchangeName)), + ->withQueueSettings(new QueueSettings($queueExchangeName, autoDelete: true)) + ->withExchangeSettings(new ExchangeSettings($queueExchangeName, autoDelete: true)), new MessageSerializer(), $this->getLoop(), ); @@ -80,7 +80,7 @@ public function testNoKeyInPayloadExceptionId(): void $queueExchangeName, $queueExchangeName, new AMQPMessage( - json_encode(['name' => 'ext-simple', 'id' => 1], JSON_THROW_ON_ERROR), + json_encode(['name' => ExtendedSimpleMessageHandler::class, 'id' => 1], JSON_THROW_ON_ERROR), ['content_type' => 'text/json', 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT] ) ); @@ -100,7 +100,7 @@ public function testNoKeyInPayloadExceptionMeta(): void $queueExchangeName, $queueExchangeName, new AMQPMessage( - json_encode(['name' => 'ext-simple', 'meta' => ''], JSON_THROW_ON_ERROR), + json_encode(['name' => ExtendedSimpleMessageHandler::class, 'meta' => ''], JSON_THROW_ON_ERROR), ['content_type' => 'text/json', 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT] ) ); diff --git a/tests/Unit/QueueFactoryTest.php b/tests/Unit/QueueFactoryTest.php index 6b2f267..730c0ef 100644 --- a/tests/Unit/QueueFactoryTest.php +++ b/tests/Unit/QueueFactoryTest.php @@ -6,6 +6,7 @@ use Yiisoft\Injector\Injector; use Yiisoft\Queue\AMQP\QueueProvider; +use Yiisoft\Queue\AMQP\Tests\Support\ExtendedSimpleMessageHandler; use Yiisoft\Queue\AMQP\Tests\Support\FileHelper; use Yiisoft\Queue\Message\Message; use Yiisoft\Queue\Middleware\CallableFactory; @@ -58,7 +59,7 @@ public function testDifferentChannel(): void $time = time(); $queue = $factory->get('channel2'); - $queue->push(new Message('ext-simple', ['file_name' => 'test-channel-run', 'payload' => ['time' => $time]])); + $queue->push(new Message(ExtendedSimpleMessageHandler::class, ['file_name' => 'test-channel-run', 'payload' => ['time' => $time]])); self::assertNull($fileHelper->get('test-channel-run')); diff --git a/tests/Unit/QueueProviderTest.php b/tests/Unit/QueueProviderTest.php index 897f257..1a711b8 100644 --- a/tests/Unit/QueueProviderTest.php +++ b/tests/Unit/QueueProviderTest.php @@ -12,6 +12,7 @@ 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\ExtendedSimpleMessageHandler; use Yiisoft\Queue\AMQP\Tests\Support\FileHelper; use Yiisoft\Queue\Message\Message; @@ -43,7 +44,7 @@ public function testWithQueueAndExchangeSettings(): void $fileHelper = new FileHelper(); $time = time(); $queue->push( - new Message('ext-simple', ['file_name' => 'test-with-queue-settings', 'payload' => ['time' => $time]]) + new Message(ExtendedSimpleMessageHandler::class, ['file_name' => 'test-with-queue-settings', 'payload' => ['time' => $time]]) ); $message = $this diff --git a/tests/Unit/QueueSettingsTest.php b/tests/Unit/QueueSettingsTest.php index 446e6db..eecae23 100644 --- a/tests/Unit/QueueSettingsTest.php +++ b/tests/Unit/QueueSettingsTest.php @@ -11,6 +11,7 @@ use Yiisoft\Queue\AMQP\QueueProvider; use Yiisoft\Queue\AMQP\Settings\Exchange as ExchangeSettings; use Yiisoft\Queue\AMQP\Settings\Queue as QueueSettings; +use Yiisoft\Queue\AMQP\Tests\Support\ExtendedSimpleMessageHandler; use Yiisoft\Queue\Message\Message; final class QueueSettingsTest extends UnitTestCase @@ -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()); @@ -92,7 +93,7 @@ public function testArgumentsXExpires(): void $this->getQueue() ->withAdapter($adapter) ->push( - new Message('ext-simple', ['payload' => time()]) + new Message(ExtendedSimpleMessageHandler::class, ['payload' => time()]) ); sleep(2); diff --git a/tests/Unit/QueueTest.php b/tests/Unit/QueueTest.php index 84f1619..b83be0a 100644 --- a/tests/Unit/QueueTest.php +++ b/tests/Unit/QueueTest.php @@ -14,9 +14,12 @@ use Yiisoft\Queue\AMQP\QueueProviderInterface; use Yiisoft\Queue\AMQP\Settings\Exchange as ExchangeSettings; use Yiisoft\Queue\AMQP\Settings\Queue as QueueSettings; +use Yiisoft\Queue\AMQP\Tests\Support\ExceptionListener; +use Yiisoft\Queue\AMQP\Tests\Support\ExtendedSimpleMessageHandler; 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\Message; use Yiisoft\Queue\Queue; @@ -34,14 +37,14 @@ public function testStatus(): void $queue = $this->getDefaultQueue($adapter); - $message = new Message('ext-simple', null); - $queue->push( + $message = new Message(ExtendedSimpleMessageHandler::class, null); + $message = $queue->push( $message, ); $this->expectException(NotImplementedException::class); $this->expectExceptionMessage("Status check is not supported by the adapter $adapterClass."); - $adapter->status($message->getId()); + $adapter->status($message->getMetadata()[IdEnvelope::MESSAGE_ID_KEY]); } /** @@ -59,7 +62,7 @@ public function testRun(): void $queue = $this->getDefaultQueue($this->getAdapter()); $queue->push( - new Message('ext-simple', ['file_name' => $fileName, 'payload' => ['time' => $time]]) + new Message(ExtendedSimpleMessageHandler::class, ['file_name' => $fileName, 'payload' => ['time' => $time]]) ); self::assertNull($fileHelper->get($fileName)); @@ -90,7 +93,7 @@ public function testListenWithException(): void $queue = $this->getDefaultQueue($adapter); $time = time(); - $queue->push(new Message('exception-listen', ['payload' => ['time' => $time]])); + $queue->push(new Message(ExceptionListener::class, ['payload' => ['time' => $time]])); $this->expectException(JobFailureException::class); @@ -110,15 +113,14 @@ public function testListen(): void $this->getQueueSettings(), ); $adapter = new Adapter( - $queueProvider - ->withChannelName('yii-queue'), + $queueProvider->withChannelName('yii-queue'), new MessageSerializer(), $mockLoop, ); $queue = $this->getDefaultQueue($adapter); $queue->push( - new Message('ext-simple', ['file_name' => 'test-listen' . $time, 'payload' => ['time' => $time]]) + new Message(ExtendedSimpleMessageHandler::class, ['file_name' => 'test-listen' . $time, 'payload' => ['time' => $time]]) ); $queue->listen(); } diff --git a/tests/Unit/UnitTestCase.php b/tests/Unit/UnitTestCase.php index 2f119c5..7cea64b 100644 --- a/tests/Unit/UnitTestCase.php +++ b/tests/Unit/UnitTestCase.php @@ -4,7 +4,6 @@ namespace Yiisoft\Queue\AMQP\Tests\Unit; -use PHPUnit\Util\Exception as PHPUnitException; use Psr\Container\ContainerInterface; use Psr\Log\NullLogger; use Yiisoft\Injector\Injector; @@ -13,12 +12,12 @@ use Yiisoft\Queue\AMQP\MessageSerializer; use Yiisoft\Queue\AMQP\QueueProvider; use Yiisoft\Queue\AMQP\Settings\Queue as QueueSettings; +use Yiisoft\Queue\AMQP\Tests\Support\ExceptionListener; use Yiisoft\Queue\AMQP\Tests\Support\ExtendedSimpleMessageHandler; use Yiisoft\Queue\AMQP\Tests\Support\FileHelper; use Yiisoft\Queue\AMQP\Tests\Support\MainTestCase; use Yiisoft\Queue\Cli\LoopInterface; use Yiisoft\Queue\Cli\SignalLoop; -use Yiisoft\Queue\Message\MessageInterface; use Yiisoft\Queue\Middleware\CallableFactory; use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareDispatcher; use Yiisoft\Queue\Middleware\Consume\MiddlewareFactoryConsume; @@ -77,7 +76,6 @@ protected function getQueue(): Queue protected function getWorker(): WorkerInterface { return $this->worker ??= new Worker( - $this->getMessageHandlers(), new NullLogger(), new Injector($this->getContainer()), $this->getContainer(), @@ -86,19 +84,6 @@ protected function getWorker(): WorkerInterface ); } - protected function getMessageHandlers(): array - { - return [ - 'ext-simple' => [new ExtendedSimpleMessageHandler(new FileHelper()), 'handle'], - 'exception-listen' => static function (MessageInterface $message) { - $data = $message->getData(); - if (null !== $data) { - throw new PHPUnitException((string) $data['payload']['time']); - } - }, - ]; - } - protected function getContainer(): ContainerInterface { return $this->container ??= new SimpleContainer($this->getContainerDefinitions()); @@ -106,7 +91,10 @@ protected function getContainer(): ContainerInterface protected function getContainerDefinitions(): array { - return []; + return [ + ExtendedSimpleMessageHandler::class => new ExtendedSimpleMessageHandler(new FileHelper()), + ExceptionListener::class => new ExceptionListener(), + ]; } protected function getConsumeMiddlewareDispatcher(): ConsumeMiddlewareDispatcher diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 18aebec..617b910 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -3,9 +3,6 @@ version: "3.5" x-php: &php volumes: - ./runtime:/app/tests/runtime - dns: - - 8.8.8.8 - - 1.1.1.1 environment: RABBITMQ_HOST: rabbitmq RABBITMQ_PORT: 5672 @@ -44,9 +41,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..89c45bd 100755 --- a/tests/yii +++ b/tests/yii @@ -3,9 +3,9 @@ use PhpAmqpLib\Connection\AMQPStreamConnection; use Psr\Log\NullLogger; +use Symfony\Component\Console\Application; use Yiisoft\Injector\Injector; 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; @@ -28,13 +28,12 @@ use Yiisoft\Queue\QueueFactory; require_once dirname(__DIR__) . '/vendor/autoload.php'; $logger = new NullLogger(); -$container = new SimpleContainer([]); +$container = new SimpleContainer([ + SimpleMessageHandler::class => new SimpleMessageHandler(new FileHelper()), +]); $injector = new Injector($container); $callableFactory = new CallableFactory($container); $worker = new \Yiisoft\Queue\Worker\Worker( - [ - 'simple' => new SimpleMessageHandler(new FileHelper()), - ], $logger, $injector, $container,