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
9 changes: 9 additions & 0 deletions stubs/InMemoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ final class InMemoryAdapter implements AdapterInterface
private array $messages = [];
private int $current = 0;

/**
* @return MessageInterface[]
* @psalm-return list<MessageInterface>
*/
public function getMessagesList(): array
{
return array_values($this->messages);
}

public function push(MessageInterface $message): MessageInterface
{
$id = count($this->messages) + $this->current;
Expand Down
48 changes: 0 additions & 48 deletions tests/App/FakeAdapter.php

This file was deleted.

4 changes: 2 additions & 2 deletions tests/Unit/Middleware/Consume/MiddlewareDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Yiisoft\Queue\Middleware\Consume\ConsumeHandlerInterface;
use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareFactory;
use Yiisoft\Queue\QueueInterface;
use Yiisoft\Queue\Tests\App\FakeAdapter;
use Yiisoft\Queue\Stubs\InMemoryAdapter;
use Yiisoft\Queue\Tests\Unit\Middleware\Consume\Support\TestCallableMiddleware;
use Yiisoft\Queue\Tests\Unit\Middleware\Consume\Support\TestMiddleware;

Expand Down Expand Up @@ -161,7 +161,7 @@ public function handleConsume(ConsumeRequest $request): ConsumeRequest
private function createDispatcher(
?ContainerInterface $container = null,
): ConsumeMiddlewareDispatcher {
$container ??= $this->createContainer([AdapterInterface::class => new FakeAdapter()]);
$container ??= $this->createContainer([AdapterInterface::class => new InMemoryAdapter()]);
$callableFactory = new CallableFactory($container);

return new ConsumeMiddlewareDispatcher(
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Middleware/Consume/MiddlewareFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Yiisoft\Queue\Middleware\Consume\ConsumeMiddlewareFactoryInterface;
use Yiisoft\Queue\Middleware\InvalidMiddlewareDefinitionException;
use Yiisoft\Queue\QueueInterface;
use Yiisoft\Queue\Tests\App\FakeAdapter;
use Yiisoft\Queue\Stubs\InMemoryAdapter;
use Yiisoft\Queue\Tests\Unit\Middleware\Consume\Support\CallableObjectMiddleware;
use Yiisoft\Queue\Tests\Unit\Middleware\Consume\Support\InvalidController;
use Yiisoft\Queue\Tests\Unit\Middleware\Consume\Support\StringCallableMiddleware;
Expand Down Expand Up @@ -199,7 +199,7 @@ public function testInvalidMiddlewareWithWrongController(): void

private function getMiddlewareFactory(?ContainerInterface $container = null): ConsumeMiddlewareFactoryInterface
{
$container ??= $this->getContainer([AdapterInterface::class => new FakeAdapter()]);
$container ??= $this->getContainer([AdapterInterface::class => new InMemoryAdapter()]);

return new ConsumeMiddlewareFactory($container, new CallableFactory($container));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Yiisoft\Queue\Middleware\FailureHandling\FailureHandlerInterface;
use Yiisoft\Queue\Middleware\FailureHandling\FailureMiddlewareFactory;
use Yiisoft\Queue\QueueInterface;
use Yiisoft\Queue\Tests\App\FakeAdapter;
use Yiisoft\Queue\Stubs\InMemoryAdapter;
use Yiisoft\Queue\Tests\Unit\Middleware\FailureHandling\Support\TestCallableMiddleware;
use Yiisoft\Queue\Tests\Unit\Middleware\FailureHandling\Support\TestMiddleware;

Expand Down Expand Up @@ -159,7 +159,7 @@ public function handleFailure(FailureHandlingRequest $request): FailureHandlingR
private function createDispatcher(
?ContainerInterface $container = null,
): FailureMiddlewareDispatcher {
$container ??= $this->createContainer([AdapterInterface::class => new FakeAdapter()]);
$container ??= $this->createContainer([AdapterInterface::class => new InMemoryAdapter()]);
$callableFactory = new CallableFactory($container);

return new FailureMiddlewareDispatcher(new FailureMiddlewareFactory($container, $callableFactory), []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Yiisoft\Queue\Middleware\FailureHandling\FailureMiddlewareInterface;
use Yiisoft\Queue\Middleware\InvalidMiddlewareDefinitionException;
use Yiisoft\Queue\QueueInterface;
use Yiisoft\Queue\Tests\App\FakeAdapter;
use Yiisoft\Queue\Stubs\InMemoryAdapter;
use Yiisoft\Queue\Tests\Unit\Middleware\FailureHandling\Support\CallableObjectMiddleware;
use Yiisoft\Queue\Tests\Unit\Middleware\FailureHandling\Support\InvalidController;
use Yiisoft\Queue\Tests\Unit\Middleware\FailureHandling\Support\StringCallableMiddleware;
Expand Down Expand Up @@ -183,7 +183,7 @@ public function testInvalidMiddlewareWithWrongController(): void

private function getMiddlewareFactory(?ContainerInterface $container = null): FailureMiddlewareFactoryInterface
{
$container ??= $this->getContainer([AdapterInterface::class => new FakeAdapter()]);
$container ??= $this->getContainer([AdapterInterface::class => new InMemoryAdapter()]);

return new FailureMiddlewareFactory($container, new CallableFactory($container));
}
Expand Down
9 changes: 4 additions & 5 deletions tests/Unit/Middleware/Push/AdapterPushHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
use PHPUnit\Framework\TestCase;
use Yiisoft\Queue\Message\GenericMessage;
use Yiisoft\Queue\Middleware\Push\AdapterPushHandler;
use Yiisoft\Queue\Tests\App\FakeAdapter;
use Yiisoft\Queue\Stubs\InMemoryAdapter;

final class AdapterPushHandlerTest extends TestCase
{
public function testHandlePushUsesAdapter(): void
{
$adapter = new FakeAdapter();
$adapter = new InMemoryAdapter();
$handler = new AdapterPushHandler($adapter);
$message = new GenericMessage('handler', 'data');

$result = $handler->handlePush($message);
$handler->handlePush($message);

self::assertSame($message, $result);
self::assertSame([$message], $adapter->pushMessages);
self::assertSame([$message], $adapter->getMessagesList());
Comment on lines 18 to +22
}
}
4 changes: 2 additions & 2 deletions tests/Unit/Middleware/Push/MiddlewareDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Yiisoft\Queue\Middleware\Push\PushHandlerInterface;
use Yiisoft\Queue\Middleware\Push\PushMiddlewareFactory;
use Yiisoft\Queue\Middleware\Push\PushMiddlewareDispatcher;
use Yiisoft\Queue\Tests\App\FakeAdapter;
use Yiisoft\Queue\Stubs\InMemoryAdapter;
use Yiisoft\Queue\Tests\Unit\Middleware\Push\Support\TestCallableMiddleware;
use Yiisoft\Queue\Tests\Unit\Middleware\Push\Support\TestMiddleware;

Expand Down Expand Up @@ -140,7 +140,7 @@ public function testResetStackOnWithMiddlewares(): void
private function createDispatcher(
?ContainerInterface $container = null,
): PushMiddlewareDispatcher {
$container ??= $this->createContainer([AdapterInterface::class => new FakeAdapter()]);
$container ??= $this->createContainer([AdapterInterface::class => new InMemoryAdapter()]);
$callableFactory = new CallableFactory($container);

return new PushMiddlewareDispatcher(
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Middleware/Push/MiddlewareFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Yiisoft\Queue\Middleware\Push\PushMiddlewareFactory;
use Yiisoft\Queue\Middleware\Push\PushMiddlewareFactoryInterface;
use Yiisoft\Queue\Middleware\Push\PushMiddlewareInterface;
use Yiisoft\Queue\Tests\App\FakeAdapter;
use Yiisoft\Queue\Stubs\InMemoryAdapter;
use Yiisoft\Queue\Tests\Unit\Middleware\Push\Support\CallableObjectMiddleware;
use Yiisoft\Queue\Tests\Unit\Middleware\Push\Support\InvalidController;
use Yiisoft\Queue\Tests\Unit\Middleware\Push\Support\StringCallableMiddleware;
Expand Down Expand Up @@ -173,7 +173,7 @@ public function testInvalidMiddlewareWithWrongController(): void

private function getMiddlewareFactory(?ContainerInterface $container = null): PushMiddlewareFactoryInterface
{
$container ??= $this->getContainer([AdapterInterface::class => new FakeAdapter()]);
$container ??= $this->getContainer([AdapterInterface::class => new InMemoryAdapter()]);

return new PushMiddlewareFactory($container, new CallableFactory($container));
}
Expand Down
5 changes: 2 additions & 3 deletions tests/Unit/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Yiisoft\Queue\Message\GenericMessage;
use Yiisoft\Queue\MessageStatus;
use Yiisoft\Queue\Stubs\InMemoryAdapter;
use Yiisoft\Queue\Tests\App\FakeAdapter;
use Yiisoft\Queue\Tests\TestCase;

use function extension_loaded;
Expand All @@ -25,12 +24,12 @@ final class QueueTest extends TestCase
{
public function testPushSuccessful(): void
{
$adapter = new FakeAdapter();
$adapter = new InMemoryAdapter();
$queue = $this->createQueue($adapter);
$message = new GenericMessage('simple', null);
$queue->push($message);

self::assertSame([$message], $adapter->pushMessages);
self::assertSame([$message], $adapter->getMessagesList());
}

public function testPushSynchronouslyProcessesMessage(): void
Expand Down
Loading