Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
build: ## Build an image from a docker-compose file.
docker-compose -f tests/docker-compose.yml up -d --build
docker compose -f tests/docker-compose.yml up -d --build
composer:
docker-compose -f tests/docker-compose.yml run php-cli composer install
docker compose -f tests/docker-compose.yml run php-cli composer install
down : ## Stop and remove containers, networks, images, and volumes.
docker-compose -f tests/docker-compose.yml down
docker compose -f tests/docker-compose.yml down
coverage: ## Run code coverage.
docker-compose -f tests/docker-compose.yml run php-cli vendor/bin/phpunit --coverage-clover /app/tests/runtime/coverage.xml
docker compose -f tests/docker-compose.yml run php-cli vendor/bin/phpunit --coverage-clover /app/tests/runtime/coverage.xml
test: ## Run tests.
make down
make build
docker-compose -f tests/docker-compose.yml run php-cli vendor/bin/phpunit
docker compose -f tests/docker-compose.yml run php-cli vendor/bin/phpunit
test-unit: ## Run unit tests.
make down
make build
docker-compose -f tests/docker-compose.yml run php-cli vendor/bin/phpunit --testsuite Unit
docker compose -f tests/docker-compose.yml run php-cli vendor/bin/phpunit --testsuite Unit
test-integration: ## Run integration tests.
make down
make build
docker-compose -f tests/docker-compose.yml run php-cli vendor/bin/phpunit --testsuite Integration
docker compose -f tests/docker-compose.yml run php-cli vendor/bin/phpunit --testsuite Integration
static-analyze: ## Run code static analyze.
make build
docker-compose -f tests/docker-compose.yml run php-cli vendor/bin/psalm --config=psalm.xml --shepherd --stats --php-version=8.1
docker compose -f tests/docker-compose.yml run php-cli vendor/bin/psalm --config=psalm.xml --shepherd --stats --php-version=8.1
rector: ## Run rector.
make build
docker-compose -f tests/docker-compose.yml run php-cli vendor/bin/rector process --config=rector.php --dry-run
docker compose -f tests/docker-compose.yml run php-cli vendor/bin/rector process --config=rector.php --dry-run
mutation: ## Run mutation tests.
make down
make build
docker-compose -f tests/docker-compose.yml run php-cli ./vendor/bin/roave-infection-static-analysis-plugin
docker compose -f tests/docker-compose.yml run php-cli ./vendor/bin/roave-infection-static-analysis-plugin
10 changes: 5 additions & 5 deletions src/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use BackedEnum;
use Yiisoft\Queue\Adapter\AdapterInterface;
use Yiisoft\Queue\Cli\LoopInterface;
use Yiisoft\Queue\JobStatus;
use Yiisoft\Queue\Message\IdEnvelope;
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Message\MessageSerializerInterface;
use Yiisoft\Queue\MessageStatus;

final class Adapter implements AdapterInterface
{
Expand Down Expand Up @@ -38,22 +38,22 @@ public function runExisting(callable $handlerCallback): void
}
}

public function status(int|string $id): JobStatus
public function status(int|string $id): MessageStatus
{
$id = (int) $id;
if ($id <= 0) {
throw new \InvalidArgumentException('This adapter IDs start with 1.');
}
Comment thread
samdark marked this conversation as resolved.
Resolved

if ($this->provider->existInReserved($id)) {
return JobStatus::RESERVED;
return MessageStatus::RESERVED;
}

if ($this->provider->existInWaiting($id)) {
return JobStatus::WAITING;
return MessageStatus::WAITING;
}

return JobStatus::DONE;
return MessageStatus::DONE;
Comment thread
samdark marked this conversation as resolved.
Resolved
}

public function push(MessageInterface $message): MessageInterface
Expand Down
12 changes: 12 additions & 0 deletions src/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,29 @@
return $this->handlerName;
}

public function getType(): string
{
return $this->handlerName;
}

public function getData(): mixed
{
return $this->data;
}

public function getMetadata(): array

Check failure on line 44 in src/Message/Message.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

MixedReturnTypeCoercion

src/Message/Message.php:44:36: MixedReturnTypeCoercion: The declared return type 'array<string, mixed>' for Yiisoft\Queue\Redis\Message\Message::getMetadata is more specific than the inferred return type 'array<array-key, mixed>' (see https://psalm.dev/197)
{
return $this->metadata;

Check failure on line 46 in src/Message/Message.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

MixedReturnTypeCoercion

src/Message/Message.php:46:16: MixedReturnTypeCoercion: The type 'array<array-key, mixed>' is more general than the declared return type 'array<string, mixed>' for Yiisoft\Queue\Redis\Message\Message::getMetadata (see https://psalm.dev/197)
}

public function withMetadata(array $metadata): static
{
$message = clone $this;
$message->metadata = $metadata;
return $message;
Comment thread
samdark marked this conversation as resolved.
Resolved
}

public static function fromData(string $handlerName, mixed $data, array $metadata = []): self

Check failure on line 56 in src/Message/Message.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

ParamNameMismatch

src/Message/Message.php:56:44: ParamNameMismatch: Argument 1 of Yiisoft\Queue\Redis\Message\Message::fromData has wrong name $handlerName, expecting $type as defined by Yiisoft\Queue\Message\MessageInterface::fromData (see https://psalm.dev/230)
{
return new self($handlerName, $data, $metadata);
}
Expand Down
14 changes: 6 additions & 8 deletions tests/Integration/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use Yiisoft\Queue\Adapter\AdapterInterface;
use Yiisoft\Queue\Cli\LoopInterface;
use Yiisoft\Queue\JobStatus;
use Yiisoft\Queue\Message\JsonMessageSerializer;
use Yiisoft\Queue\Message\Message;
use Yiisoft\Queue\Message\GenericMessage as Message;
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Message\MessageSerializerInterface;
use Yiisoft\Queue\MessageStatus;
use Yiisoft\Queue\Queue;
use Yiisoft\Queue\Redis\Adapter;
use Yiisoft\Queue\Redis\QueueProvider;
Expand Down Expand Up @@ -53,20 +53,20 @@ public function testStatus(): void
);

$status = $adapter->status($message->getId());
$this->assertEquals(JobStatus::WAITING, $status);
$this->assertEquals(MessageStatus::WAITING, $status);

$queue->run();

$status = $adapter->status($message->getId());
$this->assertEquals(JobStatus::DONE, $status);
$this->assertEquals(MessageStatus::DONE, $status);
Comment thread
samdark marked this conversation as resolved.
Resolved

$mockReserved = $this->createMock(QueueProviderInterface::class);
$mockReserved->method('existInReserved')->willReturn(true);
$adapter = new Adapter($mockReserved, new JsonMessageSerializer(), $this->getLoop());
$queue = $this->getDefaultQueue($adapter);

$status = $adapter->status('1');
$this->assertEquals(JobStatus::RESERVED, $status);
$this->assertEquals(MessageStatus::RESERVED, $status);
}

public function testListen(): void
Expand Down Expand Up @@ -109,9 +109,7 @@ public function testImmutable(): void

private function getDefaultQueue(AdapterInterface $adapter): Queue
{
return $this
->getQueue()
->withAdapter($adapter);
return $this->getQueueWithAdapter($adapter);
}

public function testAdapterStatusException()
Expand Down
32 changes: 22 additions & 10 deletions tests/Support/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Middleware\CallableFactory;
use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareDispatcher;
use Yiisoft\Queue\Middleware\Consume\MiddlewareFactoryConsume;
use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareFactory;
use Yiisoft\Queue\Middleware\FailureHandling\FailureMiddlewareDispatcher;
use Yiisoft\Queue\Middleware\FailureHandling\MiddlewareFactoryFailure;
use Yiisoft\Queue\Middleware\Push\MiddlewareFactoryPush;
use Yiisoft\Queue\Middleware\Push\PushMiddlewareDispatcher;
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\Redis\Adapter;
use Yiisoft\Queue\Redis\QueueProvider;
Expand Down Expand Up @@ -58,7 +58,18 @@ protected function getQueue(): Queue
$this->getWorker(),
$this->getLoop(),
new NullLogger(),
$this->getPushMiddlewareDispatcher()
$this->getPushMiddlewareConfig(),
);
}

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

Expand All @@ -71,6 +82,7 @@ protected function getWorker(): WorkerInterface
$this->getContainer(),
$this->getConsumeMiddlewareDispatcher(),
$this->getFailureMiddlewareDispatcher(),
new CallableFactory($this->getContainer()),
);
}

Expand Down Expand Up @@ -100,7 +112,7 @@ protected function getContainerDefinitions(): array
protected function getConsumeMiddlewareDispatcher(): ConsumeMiddlewareDispatcher
{
return new ConsumeMiddlewareDispatcher(
new MiddlewareFactoryConsume(
new ConsumeMiddlewareFactory(
$this->getContainer(),
new CallableFactory($this->getContainer()),
),
Expand All @@ -110,7 +122,7 @@ protected function getConsumeMiddlewareDispatcher(): ConsumeMiddlewareDispatcher
protected function getFailureMiddlewareDispatcher(): FailureMiddlewareDispatcher
{
return new FailureMiddlewareDispatcher(
new MiddlewareFactoryFailure(
new FailureMiddlewareFactory(
$this->getContainer(),
new CallableFactory($this->getContainer()),
),
Expand All @@ -132,10 +144,10 @@ protected function getLoop(): LoopInterface
return $this->loop ??= new SignalLoop();
}

protected function getPushMiddlewareDispatcher(): PushMiddlewareDispatcher
protected function getPushMiddlewareConfig(): PushMiddlewareConfig
{
return new PushMiddlewareDispatcher(
new MiddlewareFactoryPush(
return new PushMiddlewareConfig(
new PushMiddlewareFactory(
$this->getContainer(),
new CallableFactory($this->getContainer()),
),
Expand Down
Loading