Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
final class Message implements MessageInterface
{
/**
* @psalm-param non-empty-string $handlerName
* @psalm-param MessagePayload $payload
* @psalm-param MessageMeta $meta
*/
Expand Down Expand Up @@ -72,6 +73,7 @@ public function withMeta(array $meta): static
}

/**
* @psalm-param non-empty-string $type
* @psalm-param MessagePayload $payload
*/
public static function fromPayload(string $type, bool|int|float|string|array|null $payload): static
Expand Down
19 changes: 6 additions & 13 deletions tests/Integration/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

namespace Yiisoft\Queue\Redis\Tests\Integration;

use Yiisoft\Queue\Adapter\AdapterInterface;
use Yiisoft\Queue\Cli\LoopInterface;
use Yiisoft\Queue\Message\Serializer\JsonMessageEncoder;
use Yiisoft\Queue\Message\Serializer\MessageSerializer;
use Yiisoft\Queue\Message\GenericMessage as Message;
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Message\Serializer\MessageSerializerInterface;
use Yiisoft\Queue\MessageStatus;
use Yiisoft\Queue\Queue;
use Yiisoft\Queue\Redis\Adapter;
use Yiisoft\Queue\Redis\QueueProvider;
use Yiisoft\Queue\Redis\QueueProviderInterface;
Expand All @@ -29,15 +27,15 @@ public function testRunExisting()
$fileName = 'test-run' . $time;
$fileHelper = new FileHelper();

$queue = $this->getDefaultQueue($this->getAdapter());
$queue = $this->getProducer($this->getAdapter());

$queue->push(
new Message('ext-simple', ['file_name' => $fileName, 'payload' => ['time' => $time]]),
);

self::assertNull($fileHelper->get($fileName));

$queue->run();
$this->getConsumer($this->getAdapter())->run();

$result = $fileHelper->get($fileName);
self::assertNotNull($result);
Expand All @@ -48,7 +46,7 @@ public function testStatus(): void
{
$adapter = $this->getAdapter();

$queue = $this->getDefaultQueue($adapter);
$queue = $this->getProducer($adapter);

$message = new Message('ext-simple', null);
$message = $queue->push(
Expand All @@ -58,7 +56,7 @@ public function testStatus(): void
$status = $adapter->status($message->getId());
$this->assertEquals(MessageStatus::WAITING, $status);

$queue->run();
$this->getConsumer($adapter)->run();

$status = $adapter->status($message->getId());
$this->assertEquals(MessageStatus::DONE, $status);
Expand Down Expand Up @@ -89,15 +87,15 @@ public function testListen(): void
new MessageSerializer(new JsonMessageEncoder()),
$mockLoop,
);
$queue = $this->getDefaultQueue($adapter);
$queue = $this->getProducer($adapter);

$queue->push(
new Message('ext-simple', ['file_name' => 'test-listen' . $time, 'payload' => ['time' => $time]]),
);
$queue->push(
new Message('ext-simple', ['file_name' => 'test-listen' . $time, 'payload' => ['time' => $time]]),
);
$queue->listen();
$this->getConsumer($adapter)->listen();
}

public function testImmutable(): void
Expand Down Expand Up @@ -144,9 +142,4 @@ public function testAdapterNullMessage()
});
$this->assertTrue($notUseHandler);
}

private function getDefaultQueue(AdapterInterface $adapter): Queue
{
return $this->getQueueWithAdapter($adapter);
}
}
41 changes: 14 additions & 27 deletions tests/Support/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Log\NullLogger;
use Yiisoft\Injector\Injector;
use Yiisoft\Queue\Adapter\AdapterInterface;
use Yiisoft\Queue\Cli\LoopInterface;
use Yiisoft\Queue\AsyncQueueProducer;
use Yiisoft\Queue\Cli\SignalLoop;
use Yiisoft\Queue\Message\Serializer\JsonMessageEncoder;
use Yiisoft\Queue\Message\Serializer\MessageSerializer;
use Yiisoft\Queue\Message\Handler\HandlerResolver;
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Middleware\CallableFactory;
use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareDispatcher;
use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareFactory;
use Yiisoft\Queue\Middleware\FailureHandling\FailureMiddlewareDispatcher;
use Yiisoft\Queue\Middleware\FailureHandling\FailureMiddlewareFactory;
use Yiisoft\Queue\Middleware\Push\PushMiddlewareConfig;
use Yiisoft\Queue\Middleware\Push\PushMiddlewareFactory;
use Yiisoft\Queue\Queue;
use Yiisoft\Queue\QueueConsumer;
use Yiisoft\Queue\QueueConsumerInterface;
use Yiisoft\Queue\QueueProducerInterface;
use Yiisoft\Queue\Redis\Adapter;
use Yiisoft\Queue\Redis\QueueProvider;
use Yiisoft\Queue\Worker\Worker;
Expand All @@ -40,7 +42,6 @@
abstract class IntegrationTestCase extends TestCase
{
public ?QueueProvider $queueProvider = null;
protected ?Queue $queue = null;
protected ?WorkerInterface $worker = null;
protected ?ContainerInterface $container = null;
protected ?AdapterInterface $adapter = null;
Expand All @@ -59,37 +60,32 @@ protected function tearDown(): void
parent::tearDown();
}

protected function getQueue(): Queue
protected function getProducer(AdapterInterface $adapter): QueueProducerInterface
{
return $this->queue ??= new Queue(
$this->getWorker(),
$this->getLoop(),
return new AsyncQueueProducer(
new NullLogger(),
$this->getPushMiddlewareConfig(),
$adapter,
);
}

protected function getQueueWithAdapter(AdapterInterface $adapter): Queue
protected function getConsumer(AdapterInterface $adapter): QueueConsumerInterface
{
return new Queue(
return new QueueConsumer(
$this->getWorker(),
$this->getLoop(),
new NullLogger(),
$this->getPushMiddlewareConfig(),
$adapter,
);
}

protected function getWorker(): WorkerInterface
{
return $this->worker ??= new Worker(
$this->getMessageHandlers(),
new NullLogger(),
new Injector($this->getContainer()),
$this->getContainer(),
$this->getConsumeMiddlewareDispatcher(),
$this->getFailureMiddlewareDispatcher(),
new CallableFactory($this->getContainer()),
new HandlerResolver($this->getMessageHandlers(), $this->getContainer()),
);
}

Expand Down Expand Up @@ -123,20 +119,14 @@ protected function getContainerDefinitions(): array
protected function getConsumeMiddlewareDispatcher(): ConsumeMiddlewareDispatcher
{
return new ConsumeMiddlewareDispatcher(
new ConsumeMiddlewareFactory(
$this->getContainer(),
new CallableFactory($this->getContainer()),
),
new ConsumeMiddlewareFactory($this->getContainer()),
);
}

protected function getFailureMiddlewareDispatcher(): FailureMiddlewareDispatcher
{
return new FailureMiddlewareDispatcher(
new FailureMiddlewareFactory(
$this->getContainer(),
new CallableFactory($this->getContainer()),
),
new FailureMiddlewareFactory($this->getContainer()),
[],
);
}
Expand All @@ -158,10 +148,7 @@ protected function getLoop(): LoopInterface
protected function getPushMiddlewareConfig(): PushMiddlewareConfig
{
return new PushMiddlewareConfig(
new PushMiddlewareFactory(
$this->getContainer(),
new CallableFactory($this->getContainer()),
),
new PushMiddlewareFactory($this->getContainer()),
);
}

Expand Down
Loading