From 904173262bea71d74c913f780f962ce9d003b947 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 1 Apr 2026 17:19:43 +0300 Subject: [PATCH 1/3] Remove `QueueInterface::withAdapter()` --- src/Debug/QueueDecorator.php | 7 - .../AdapterNotConfiguredException.php | 38 ---- src/Middleware/Push/AdapterPushHandler.php | 11 +- src/Middleware/Push/PushRequest.php | 7 +- src/Provider/AdapterFactoryQueueProvider.php | 113 ------------ src/Queue.php | 30 +--- src/QueueInterface.php | 10 -- stubs/StubQueue.php | 29 +-- tests/App/DummyQueue.php | 5 - tests/Integration/MiddlewareTest.php | 3 +- tests/TestCase.php | 12 +- tests/Unit/Adapter/SynchronousAdapterTest.php | 26 ++- tests/Unit/Debug/QueueDecoratorTest.php | 25 --- .../Push/AdapterPushHandlerTest.php | 10 -- .../Push/Implementation/IdMiddlewareTest.php | 5 +- .../AdapterFactoryQueueProviderTest.php | 169 ------------------ tests/Unit/QueueTest.php | 58 +----- tests/Unit/Stubs/StubQueueTest.php | 11 -- 18 files changed, 50 insertions(+), 519 deletions(-) delete mode 100644 src/Exception/AdapterConfiguration/AdapterNotConfiguredException.php delete mode 100644 src/Provider/AdapterFactoryQueueProvider.php delete mode 100644 tests/Unit/Provider/AdapterFactoryQueueProviderTest.php diff --git a/src/Debug/QueueDecorator.php b/src/Debug/QueueDecorator.php index f0bc7353..b62f9b82 100644 --- a/src/Debug/QueueDecorator.php +++ b/src/Debug/QueueDecorator.php @@ -4,8 +4,6 @@ namespace Yiisoft\Queue\Debug; -use BackedEnum; -use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\JobStatus; use Yiisoft\Queue\Message\MessageInterface; use Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface; @@ -45,11 +43,6 @@ public function listen(): void $this->queue->listen(); } - public function withAdapter(AdapterInterface $adapter, string|BackedEnum|null $queueName = null): static - { - return new self($this->queue->withAdapter($adapter, $queueName), $this->collector); - } - public function getName(): string { return $this->queue->getName(); diff --git a/src/Exception/AdapterConfiguration/AdapterNotConfiguredException.php b/src/Exception/AdapterConfiguration/AdapterNotConfiguredException.php deleted file mode 100644 index 4e91096e..00000000 --- a/src/Exception/AdapterConfiguration/AdapterNotConfiguredException.php +++ /dev/null @@ -1,38 +0,0 @@ -getAdapter()) === null) { - throw new AdapterNotConfiguredException(); - } - return $request->withMessage($adapter->push($request->getMessage())); + return $request->withMessage( + $request->getAdapter()->push( + $request->getMessage(), + ), + ); } } diff --git a/src/Middleware/Push/PushRequest.php b/src/Middleware/Push/PushRequest.php index 09aaed9b..88786876 100644 --- a/src/Middleware/Push/PushRequest.php +++ b/src/Middleware/Push/PushRequest.php @@ -9,14 +9,17 @@ final class PushRequest { - public function __construct(private MessageInterface $message, private ?AdapterInterface $adapter) {} + public function __construct( + private MessageInterface $message, + private AdapterInterface $adapter, + ) {} public function getMessage(): MessageInterface { return $this->message; } - public function getAdapter(): ?AdapterInterface + public function getAdapter(): AdapterInterface { return $this->adapter; } diff --git a/src/Provider/AdapterFactoryQueueProvider.php b/src/Provider/AdapterFactoryQueueProvider.php deleted file mode 100644 index 11a187fe..00000000 --- a/src/Provider/AdapterFactoryQueueProvider.php +++ /dev/null @@ -1,113 +0,0 @@ - - */ - private array $queues = []; - - private readonly StrictFactory $factory; - - /** - * @psalm-var list - */ - private readonly array $names; - - /** - * @param QueueInterface $baseQueue Base queue for queues creation. - * @param array $definitions Adapter definitions indexed by queue names. - * @param ContainerInterface|null $container Container to use for dependencies resolving. - * @param bool $validate If definitions should be validated when set. - * - * @psalm-param array $definitions - * @throws InvalidQueueConfigException - */ - public function __construct( - private readonly QueueInterface $baseQueue, - array $definitions, - ?ContainerInterface $container = null, - bool $validate = true, - ) { - $this->names = array_keys($definitions); - try { - $this->factory = new StrictFactory($definitions, $container, $validate); - } catch (InvalidConfigException $exception) { - throw new InvalidQueueConfigException($exception->getMessage(), previous: $exception); - } - } - - public function get(string|BackedEnum $name): QueueInterface - { - $name = StringNormalizer::normalize($name); - - $queue = $this->getOrTryToCreate($name); - if ($queue === null) { - throw new QueueNotFoundException($name); - } - - return $queue; - } - - public function has(string|BackedEnum $name): bool - { - $name = StringNormalizer::normalize($name); - return $this->factory->has($name); - } - - public function getNames(): array - { - return $this->names; - } - - /** - * @throws InvalidQueueConfigException - */ - private function getOrTryToCreate(string $name): ?QueueInterface - { - if (array_key_exists($name, $this->queues)) { - return $this->queues[$name]; - } - - if ($this->factory->has($name)) { - $adapter = $this->factory->create($name); - if (!$adapter instanceof AdapterInterface) { - throw new InvalidQueueConfigException( - sprintf( - 'Adapter must implement "%s". For queue "%s" got "%s" instead.', - AdapterInterface::class, - $name, - get_debug_type($adapter), - ), - ); - } - $this->queues[$name] = $this->baseQueue->withAdapter($adapter, $name); - } else { - $this->queues[$name] = null; - } - - return $this->queues[$name]; - } -} diff --git a/src/Queue.php b/src/Queue.php index 76bb68a3..a04db37e 100644 --- a/src/Queue.php +++ b/src/Queue.php @@ -8,7 +8,6 @@ use Psr\Log\LoggerInterface; use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\Cli\LoopInterface; -use Yiisoft\Queue\Exception\AdapterConfiguration\AdapterNotConfiguredException; use Yiisoft\Queue\Message\MessageInterface; use Yiisoft\Queue\Middleware\Push\AdapterPushHandler; use Yiisoft\Queue\Middleware\Push\MessageHandlerPushInterface; @@ -33,8 +32,8 @@ public function __construct( private readonly LoopInterface $loop, private readonly LoggerInterface $logger, private readonly PushMiddlewareDispatcher $pushMiddlewareDispatcher, + private readonly AdapterInterface $adapter, string|BackedEnum $name = QueueProviderInterface::DEFAULT_QUEUE, - private ?AdapterInterface $adapter = null, MiddlewarePushInterface|callable|array|string ...$middlewareDefinitions, ) { $this->name = StringNormalizer::normalize($name); @@ -51,7 +50,6 @@ public function push( MessageInterface $message, MiddlewarePushInterface|callable|array|string ...$middlewareDefinitions, ): MessageInterface { - $this->checkAdapter(); $this->logger->debug( 'Preparing to push message with handler name "{handlerName}".', ['handlerName' => $message->getHandlerName()], @@ -74,8 +72,6 @@ public function push( public function run(int $max = 0): int { - $this->checkAdapter(); - $this->logger->debug('Start processing queue messages.'); $count = 0; @@ -100,8 +96,6 @@ public function run(int $max = 0): int public function listen(): void { - $this->checkAdapter(); - $this->logger->info('Start listening to the queue.'); $this->adapter->subscribe(fn(MessageInterface $message) => $this->handle($message)); $this->logger->info('Finish listening to the queue.'); @@ -109,21 +103,9 @@ public function listen(): void public function status(string|int $id): JobStatus { - $this->checkAdapter(); return $this->adapter->status($id); } - public function withAdapter(AdapterInterface $adapter, string|BackedEnum|null $queueName = null): static - { - $new = clone $this; - $new->adapter = $adapter; - if ($queueName !== null) { - $new->name = StringNormalizer::normalize($queueName); - } - - return $new; - } - public function withMiddlewares(MiddlewarePushInterface|callable|array|string ...$middlewareDefinitions): self { $instance = clone $this; @@ -147,16 +129,6 @@ private function handle(MessageInterface $message): bool return $this->loop->canContinue(); } - /** - * @psalm-assert AdapterInterface $this->adapter - */ - private function checkAdapter(): void - { - if ($this->adapter === null) { - throw new AdapterNotConfiguredException(); - } - } - private function createPushHandler(MiddlewarePushInterface|callable|array|string ...$middlewares): MessageHandlerPushInterface { return new class ( diff --git a/src/QueueInterface.php b/src/QueueInterface.php index d73a06e9..77aa7d1b 100644 --- a/src/QueueInterface.php +++ b/src/QueueInterface.php @@ -4,9 +4,7 @@ namespace Yiisoft\Queue; -use BackedEnum; use InvalidArgumentException; -use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\Message\MessageInterface; use Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface; @@ -41,14 +39,6 @@ public function listen(): void; */ public function status(string|int $id): JobStatus; - /** - * @param AdapterInterface $adapter Adapter to use. - * @param string|BackedEnum|null $queueName Queue name to use. - * - * @return static A new queue with the given adapter and queue name. - */ - public function withAdapter(AdapterInterface $adapter, string|BackedEnum|null $queueName = null): static; - /** * Returns the logical name of the queue. */ diff --git a/stubs/StubQueue.php b/stubs/StubQueue.php index 41ae0a82..c325d99d 100644 --- a/stubs/StubQueue.php +++ b/stubs/StubQueue.php @@ -4,13 +4,11 @@ namespace Yiisoft\Queue\Stubs; -use BackedEnum; use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\JobStatus; use Yiisoft\Queue\Message\MessageInterface; use Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface; use Yiisoft\Queue\QueueInterface; -use Yiisoft\Queue\StringNormalizer; /** * Stub queue that does nothing. Job status is always "done". @@ -24,13 +22,12 @@ final class StubQueue implements QueueInterface */ public function __construct( private ?AdapterInterface $adapter = null, - private string $name = 'default' - ) { - } + private string $name = 'default', + ) {} public function push( MessageInterface $message, - string|array|callable|MiddlewarePushInterface ...$middlewareDefinitions + string|array|callable|MiddlewarePushInterface ...$middlewareDefinitions, ): MessageInterface { return $message; } @@ -40,9 +37,7 @@ public function run(int $max = 0): int return 0; } - public function listen(): void - { - } + public function listen(): void {} public function status(int|string $id): JobStatus { @@ -57,22 +52,6 @@ public function getAdapter(): ?AdapterInterface return $this->adapter; } - /** - * @param T $adapter - * @return static - */ - public function withAdapter(AdapterInterface $adapter, string|BackedEnum|null $queueName = null): static - { - $new = clone $this; - $new->adapter = $adapter; - - if ($queueName !== null) { - $new->name = StringNormalizer::normalize($queueName); - } - - return $new; - } - public function getName(): string { return $this->name; diff --git a/tests/App/DummyQueue.php b/tests/App/DummyQueue.php index f15ee673..6727abb9 100644 --- a/tests/App/DummyQueue.php +++ b/tests/App/DummyQueue.php @@ -37,11 +37,6 @@ public function status(string|int $id): JobStatus throw new Exception('`status()` method is not implemented yet.'); } - public function withAdapter(AdapterInterface $adapter, string|BackedEnum|null $queueName = null): static - { - throw new Exception('`withAdapter()` method is not implemented yet.'); - } - public function getName(): string { return $this->name; diff --git a/tests/Integration/MiddlewareTest.php b/tests/Integration/MiddlewareTest.php index 02e02ddf..0732ff9a 100644 --- a/tests/Integration/MiddlewareTest.php +++ b/tests/Integration/MiddlewareTest.php @@ -9,6 +9,7 @@ use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Yiisoft\Injector\Injector; +use Yiisoft\Queue\Stubs\StubAdapter; use Yiisoft\Test\Support\Container\SimpleContainer; use Yiisoft\Test\Support\Log\SimpleLogger; use Yiisoft\Queue\Adapter\SynchronousAdapter; @@ -63,11 +64,11 @@ public function testFullStackPush(): void $this->createMock(LoopInterface::class), $this->createMock(LoggerInterface::class), $pushMiddlewareDispatcher, - 'test', new SynchronousAdapter( $this->createMock(WorkerInterface::class), $this->createMock(QueueInterface::class), ), + 'test', ); $queue = $queue ->withMiddlewares(new TestMiddleware('Won\'t be executed')) diff --git a/tests/TestCase.php b/tests/TestCase.php index c7bb2c75..77137a7e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,12 +4,16 @@ namespace Yiisoft\Queue\Tests; +use BackedEnum; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase as BaseTestCase; use Psr\Container\ContainerInterface; use Psr\Log\NullLogger; use RuntimeException; use Yiisoft\Injector\Injector; +use Yiisoft\Queue\Provider\QueueProviderInterface; +use Yiisoft\Queue\Stubs\StubAdapter; +use Yiisoft\Queue\Tests\App\FakeAdapter; use Yiisoft\Test\Support\Container\SimpleContainer; use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\Adapter\SynchronousAdapter; @@ -103,13 +107,17 @@ protected function getContainer(): ContainerInterface return $this->container; } - protected function createQueue(): Queue - { + protected function createQueue( + AdapterInterface $adapter = new StubAdapter(), + string|BackedEnum $name = QueueProviderInterface::DEFAULT_QUEUE, + ): Queue { return new Queue( $this->getWorker(), $this->getLoop(), new NullLogger(), $this->getPushMiddlewareDispatcher(), + $adapter, + $name, ); } diff --git a/tests/Unit/Adapter/SynchronousAdapterTest.php b/tests/Unit/Adapter/SynchronousAdapterTest.php index 52deb0b1..b16c0db1 100644 --- a/tests/Unit/Adapter/SynchronousAdapterTest.php +++ b/tests/Unit/Adapter/SynchronousAdapterTest.php @@ -5,32 +5,33 @@ namespace Yiisoft\Queue\Tests\Unit\Adapter; use InvalidArgumentException; +use PHPUnit\Framework\TestCase; +use Yiisoft\Queue\Adapter\SynchronousAdapter; use Yiisoft\Queue\JobStatus; use Yiisoft\Queue\Message\IdEnvelope; use Yiisoft\Queue\Message\Message; -use Yiisoft\Queue\Tests\TestCase; +use Yiisoft\Queue\Stubs\StubQueue; +use Yiisoft\Queue\Stubs\StubWorker; final class SynchronousAdapterTest extends TestCase { public function testNonIntegerId(): void { - $queue = $this - ->getQueue() - ->withAdapter($this->getAdapter()); + $adapter = new SynchronousAdapter(new StubWorker(), new StubQueue()); $message = new Message('simple', null); - $envelope = $queue->push($message); + $envelope = $adapter->push($message); self::assertArrayHasKey(IdEnvelope::MESSAGE_ID_KEY, $envelope->getMetadata()); $id = $envelope->getMetadata()[IdEnvelope::MESSAGE_ID_KEY]; $wrongId = "$id "; - self::assertSame(JobStatus::WAITING, $queue->status($wrongId)); + self::assertSame(JobStatus::WAITING, $adapter->status($wrongId)); } public function testIdSetting(): void { $message = new Message('simple', []); - $adapter = $this->getAdapter(); + $adapter = new SynchronousAdapter(new StubWorker(), new StubQueue()); $ids = []; $envelope = $adapter->push($message); @@ -45,7 +46,8 @@ public function testIdSetting(): void public function testStatusIdLessZero(): void { - $adapter = $this->getAdapter(); + $adapter = new SynchronousAdapter(new StubWorker(), new StubQueue()); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('This adapter IDs start with 0.'); $adapter->status('-1'); @@ -53,14 +55,10 @@ public function testStatusIdLessZero(): void public function testStatusNotMessage(): void { - $adapter = $this->getAdapter(); + $adapter = new SynchronousAdapter(new StubWorker(), new StubQueue()); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('There is no message with the given ID.'); $adapter->status('1'); } - - protected function needsRealAdapter(): bool - { - return true; - } } diff --git a/tests/Unit/Debug/QueueDecoratorTest.php b/tests/Unit/Debug/QueueDecoratorTest.php index 8d10822b..a663c1c0 100644 --- a/tests/Unit/Debug/QueueDecoratorTest.php +++ b/tests/Unit/Debug/QueueDecoratorTest.php @@ -15,22 +15,6 @@ class QueueDecoratorTest extends TestCase { - public function testWithAdapter(): void - { - $queue = $this->createMock(QueueInterface::class); - $collector = new QueueCollector(); - $decorator = new QueueDecorator( - $queue, - $collector, - ); - - $queueAdapter = $this->createMock(AdapterInterface::class); - - $newDecorator = $decorator->withAdapter($queueAdapter); - - $this->assertInstanceOf(QueueDecorator::class, $newDecorator); - } - public function testStatus(): void { $queue = $this->createMock(QueueInterface::class); @@ -98,13 +82,4 @@ public function testGetName(): void $this->assertEquals('hello', $decorator->getName()); } - - public function testImmutable(): void - { - $queueDecorator = new QueueDecorator( - $this->createMock(QueueInterface::class), - new QueueCollector(), - ); - $this->assertNotSame($queueDecorator, $queueDecorator->withAdapter(new FakeAdapter())); - } } diff --git a/tests/Unit/Middleware/Push/AdapterPushHandlerTest.php b/tests/Unit/Middleware/Push/AdapterPushHandlerTest.php index 3d41ecbb..db2158ea 100644 --- a/tests/Unit/Middleware/Push/AdapterPushHandlerTest.php +++ b/tests/Unit/Middleware/Push/AdapterPushHandlerTest.php @@ -5,7 +5,6 @@ namespace Yiisoft\Queue\Tests\Unit\Middleware\Push; use PHPUnit\Framework\TestCase; -use Yiisoft\Queue\Exception\AdapterConfiguration\AdapterNotConfiguredException; use Yiisoft\Queue\Message\Message; use Yiisoft\Queue\Middleware\Push\AdapterPushHandler; use Yiisoft\Queue\Middleware\Push\PushRequest; @@ -13,15 +12,6 @@ final class AdapterPushHandlerTest extends TestCase { - public function testHandlePushThrowsWhenNoAdapter(): void - { - $handler = new AdapterPushHandler(); - $request = new PushRequest(new Message('handler', 'data'), null); - - $this->expectException(AdapterNotConfiguredException::class); - $handler->handlePush($request); - } - public function testHandlePushUsesAdapter(): void { $handler = new AdapterPushHandler(); diff --git a/tests/Unit/Middleware/Push/Implementation/IdMiddlewareTest.php b/tests/Unit/Middleware/Push/Implementation/IdMiddlewareTest.php index c2f72513..071b8892 100644 --- a/tests/Unit/Middleware/Push/Implementation/IdMiddlewareTest.php +++ b/tests/Unit/Middleware/Push/Implementation/IdMiddlewareTest.php @@ -10,13 +10,14 @@ use Yiisoft\Queue\Middleware\Push\Implementation\IdMiddleware; use Yiisoft\Queue\Middleware\Push\MessageHandlerPushInterface; use Yiisoft\Queue\Middleware\Push\PushRequest; +use Yiisoft\Queue\Stubs\StubAdapter; final class IdMiddlewareTest extends TestCase { public function testWithId(): void { $message = new Message('test', null, [IdEnvelope::MESSAGE_ID_KEY => 'test-id']); - $originalRequest = new PushRequest($message, null); + $originalRequest = new PushRequest($message, new StubAdapter()); $handler = $this->createMock(MessageHandlerPushInterface::class); $handler->expects($this->once()) @@ -36,7 +37,7 @@ public function testWithId(): void public function testWithoutId(): void { $message = new Message('test', null); - $originalRequest = new PushRequest($message, null); + $originalRequest = new PushRequest($message, new StubAdapter()); $handler = $this->createMock(MessageHandlerPushInterface::class); $handler->expects($this->once()) diff --git a/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php b/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php deleted file mode 100644 index d2a7521d..00000000 --- a/tests/Unit/Provider/AdapterFactoryQueueProviderTest.php +++ /dev/null @@ -1,169 +0,0 @@ - StubAdapter::class, - ], - ); - - /** @var StubQueue $queue */ - $queue = $provider->get('queue1'); - - $this->assertInstanceOf(StubQueue::class, $queue); - $this->assertSame('queue1', $queue->getName()); - $this->assertInstanceOf(StubAdapter::class, $queue->getAdapter()); - $this->assertTrue($provider->has('queue1')); - $this->assertFalse($provider->has('not-exist-queue')); - } - - public function testGetTwice(): void - { - $provider = new AdapterFactoryQueueProvider( - new StubQueue(), - [ - 'queue1' => StubAdapter::class, - ], - ); - - $queue1 = $provider->get('queue1'); - $queue2 = $provider->get('queue1'); - - $this->assertSame($queue1, $queue2); - } - - public function testGetNotExistQueue(): void - { - $provider = new AdapterFactoryQueueProvider( - new StubQueue(), - [ - 'queue1' => StubAdapter::class, - ], - ); - - $this->expectException(QueueNotFoundException::class); - $this->expectExceptionMessage('Queue with name "not-exist-queue" not found.'); - $provider->get('not-exist-queue'); - } - - public function testInvalidQueueConfig(): void - { - $baseQueue = new StubQueue(); - $definitions = [ - 'queue1' => [ - 'class' => StubAdapter::class, - '__construct()' => 'hello', - ], - ]; - - $this->expectException(InvalidQueueConfigException::class); - $this->expectExceptionMessage( - 'Invalid definition: incorrect constructor arguments. Expected array, got string.', - ); - new AdapterFactoryQueueProvider($baseQueue, $definitions); - } - - public function testInvalidQueueConfigOnGet(): void - { - $provider = new AdapterFactoryQueueProvider( - new StubQueue(), - [ - 'queue1' => StubLoop::class, - ], - ); - - $this->expectException(InvalidQueueConfigException::class); - $this->expectExceptionMessage( - sprintf( - 'Adapter must implement "%s". For queue "%s" got "%s" instead.', - AdapterInterface::class, - 'queue1', - StubLoop::class, - ), - ); - $provider->get('queue1'); - } - - public function testGetHasByStringEnum(): void - { - $provider = new AdapterFactoryQueueProvider( - new StubQueue(), - [ - 'red' => StubAdapter::class, - ], - ); - - $queue = $provider->get(StringEnum::RED); - - $this->assertSame('red', $queue->getName()); - $this->assertTrue($provider->has(StringEnum::RED)); - $this->assertFalse($provider->has(StringEnum::GREEN)); - } - - public function testQueueNameAndAdapterConfiguration(): void - { - $provider = new AdapterFactoryQueueProvider( - new StubQueue(), - [ - 'mail-queue' => [ - 'class' => StubAdapter::class, - ], - 'log-queue' => StubAdapter::class, - ], - ); - - /** @var StubQueue $mailQueue */ - $mailQueue = $provider->get('mail-queue'); - /** @var StubQueue $logQueue */ - $logQueue = $provider->get('log-queue'); - - $this->assertSame('mail-queue', $mailQueue->getName()); - $this->assertInstanceOf(StubAdapter::class, $mailQueue->getAdapter()); - - $this->assertSame('log-queue', $logQueue->getName()); - $this->assertInstanceOf(StubAdapter::class, $logQueue->getAdapter()); - } - - public function testGetNames(): void - { - $provider = new AdapterFactoryQueueProvider( - new StubQueue(), - [ - 'queue1' => StubAdapter::class, - 'queue2' => StubAdapter::class, - ], - ); - - $this->assertSame(['queue1', 'queue2'], $provider->getNames()); - } - - public function testGetNamesEmpty(): void - { - $provider = new AdapterFactoryQueueProvider( - new StubQueue(), - [], - ); - - $this->assertSame([], $provider->getNames()); - } -} diff --git a/tests/Unit/QueueTest.php b/tests/Unit/QueueTest.php index c69c940a..b4629ef4 100644 --- a/tests/Unit/QueueTest.php +++ b/tests/Unit/QueueTest.php @@ -5,7 +5,6 @@ namespace Yiisoft\Queue\Tests\Unit; use Yiisoft\Queue\Cli\SignalLoop; -use Yiisoft\Queue\Exception\AdapterConfiguration\AdapterNotConfiguredException; use Yiisoft\Queue\JobStatus; use Yiisoft\Queue\Message\Message; use Yiisoft\Queue\Stubs\StubAdapter; @@ -36,9 +35,7 @@ protected function setUp(): void public function testPushSuccessful(): void { $adapter = new FakeAdapter(); - $queue = $this - ->getQueue() - ->withAdapter($adapter); + $queue = $this->createQueue($adapter); $message = new Message('simple', null); $queue->push($message); @@ -47,9 +44,7 @@ public function testPushSuccessful(): void public function testRun(): void { - $queue = $this - ->getQueue() - ->withAdapter($this->getAdapter()); + $queue = $this->createQueue($this->getAdapter()); $message = new Message('simple', null); $message2 = clone $message; $queue->push($message); @@ -62,9 +57,7 @@ public function testRun(): void public function testRunPartly(): void { $message = new Message('simple', null); - $queue = $this - ->getQueue() - ->withAdapter($this->getAdapter()); + $queue = $this->createQueue($this->getAdapter()); $message2 = clone $message; $queue->push($message); $queue->push($message2); @@ -75,9 +68,7 @@ public function testRunPartly(): void public function testListen(): void { - $queue = $this - ->getQueue() - ->withAdapter($this->getAdapter()); + $queue = $this->createQueue($this->getAdapter()); $message = new Message('simple', null); $message2 = clone $message; $queue->push($message); @@ -89,9 +80,7 @@ public function testListen(): void public function testStatus(): void { - $queue = $this - ->getQueue() - ->withAdapter($this->getAdapter()); + $queue = $this->createQueue($this->getAdapter()); $message = new Message('simple', null); $envelope = $queue->push($message); @@ -109,31 +98,6 @@ public function testStatus(): void self::assertSame(JobStatus::DONE, $status); } - public function testAdapterNotConfiguredException(): void - { - try { - $queue = $this->getQueue(); - $message = new Message('simple', null); - $envelope = $queue->push($message); - $queue->status($envelope->getMetadata()[IdEnvelope::MESSAGE_ID_KEY]); - } catch (AdapterNotConfiguredException $exception) { - self::assertSame($exception::class, AdapterNotConfiguredException::class); - self::assertSame($exception->getName(), 'Adapter is not configured'); - $this->assertMatchesRegularExpression('/withAdapter/', $exception->getSolution()); - } - } - - public function testAdapterNotConfiguredExceptionForRun(): void - { - try { - $this->getQueue()->run(); - } catch (AdapterNotConfiguredException $exception) { - self::assertSame($exception::class, AdapterNotConfiguredException::class); - self::assertSame($exception->getName(), 'Adapter is not configured'); - $this->assertMatchesRegularExpression('/withAdapter/', $exception->getSolution()); - } - } - public function testRunWithSignalLoop(): void { if (!extension_loaded('pcntl')) { @@ -141,9 +105,7 @@ public function testRunWithSignalLoop(): void } $this->loop = new SignalLoop(); - $queue = $this - ->getQueue() - ->withAdapter($this->getAdapter()); + $queue = $this->createQueue($this->getAdapter()); $message = new Message('simple', null); $message2 = clone $message; $queue->push($message); @@ -155,18 +117,14 @@ public function testRunWithSignalLoop(): void public function testGetName(): void { - $queue = $this - ->getQueue() - ->withAdapter(new StubAdapter(), 'test-queue'); + $queue = $this->createQueue(name: 'test-queue'); $this->assertSame('test-queue', $queue->getName()); } public function testGetNameWithBackedEnum(): void { - $queue = $this - ->getQueue() - ->withAdapter(new StubAdapter(), TestQueue::HIGH_PRIORITY); + $queue = $this->createQueue(name: TestQueue::HIGH_PRIORITY); $this->assertSame('high-priority', $queue->getName()); } diff --git a/tests/Unit/Stubs/StubQueueTest.php b/tests/Unit/Stubs/StubQueueTest.php index 63f61ff6..bd1521a3 100644 --- a/tests/Unit/Stubs/StubQueueTest.php +++ b/tests/Unit/Stubs/StubQueueTest.php @@ -8,7 +8,6 @@ use Yiisoft\Queue\JobStatus; use Yiisoft\Queue\Message\Message; use Yiisoft\Queue\Stubs\StubQueue; -use Yiisoft\Queue\Stubs\StubAdapter; final class StubQueueTest extends TestCase { @@ -23,14 +22,4 @@ public function testBase(): void $this->assertNull($queue->getAdapter()); $queue->listen(); } - - public function testWithAdapter(): void - { - $sourceQueue = new StubQueue(); - - $queue = $sourceQueue->withAdapter(new StubAdapter()); - - $this->assertNotSame($queue, $sourceQueue); - $this->assertInstanceOf(StubAdapter::class, $queue->getAdapter()); - } } From 77fbe0b42bd779eb019f220695ae13fb46f9ca87 Mon Sep 17 00:00:00 2001 From: vjik <525501+vjik@users.noreply.github.com> Date: Thu, 2 Apr 2026 13:41:00 +0000 Subject: [PATCH 2/3] Apply PHP CS Fixer and Rector changes (CI) --- tests/App/DummyQueue.php | 2 -- tests/Integration/MiddlewareTest.php | 1 - tests/TestCase.php | 1 - tests/Unit/Debug/QueueDecoratorTest.php | 2 -- tests/Unit/QueueTest.php | 1 - 5 files changed, 7 deletions(-) diff --git a/tests/App/DummyQueue.php b/tests/App/DummyQueue.php index 6727abb9..1b5d827e 100644 --- a/tests/App/DummyQueue.php +++ b/tests/App/DummyQueue.php @@ -4,9 +4,7 @@ namespace Yiisoft\Queue\Tests\App; -use BackedEnum; use Exception; -use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\JobStatus; use Yiisoft\Queue\Message\MessageInterface; use Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface; diff --git a/tests/Integration/MiddlewareTest.php b/tests/Integration/MiddlewareTest.php index 0732ff9a..a9967af2 100644 --- a/tests/Integration/MiddlewareTest.php +++ b/tests/Integration/MiddlewareTest.php @@ -9,7 +9,6 @@ use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Yiisoft\Injector\Injector; -use Yiisoft\Queue\Stubs\StubAdapter; use Yiisoft\Test\Support\Container\SimpleContainer; use Yiisoft\Test\Support\Log\SimpleLogger; use Yiisoft\Queue\Adapter\SynchronousAdapter; diff --git a/tests/TestCase.php b/tests/TestCase.php index 77137a7e..c687477e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -13,7 +13,6 @@ use Yiisoft\Injector\Injector; use Yiisoft\Queue\Provider\QueueProviderInterface; use Yiisoft\Queue\Stubs\StubAdapter; -use Yiisoft\Queue\Tests\App\FakeAdapter; use Yiisoft\Test\Support\Container\SimpleContainer; use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\Adapter\SynchronousAdapter; diff --git a/tests/Unit/Debug/QueueDecoratorTest.php b/tests/Unit/Debug/QueueDecoratorTest.php index a663c1c0..a4c17113 100644 --- a/tests/Unit/Debug/QueueDecoratorTest.php +++ b/tests/Unit/Debug/QueueDecoratorTest.php @@ -5,13 +5,11 @@ namespace Yiisoft\Queue\Tests\Unit\Debug; use PHPUnit\Framework\TestCase; -use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\Debug\QueueCollector; use Yiisoft\Queue\Debug\QueueDecorator; use Yiisoft\Queue\JobStatus; use Yiisoft\Queue\Message\MessageInterface; use Yiisoft\Queue\QueueInterface; -use Yiisoft\Queue\Tests\App\FakeAdapter; class QueueDecoratorTest extends TestCase { diff --git a/tests/Unit/QueueTest.php b/tests/Unit/QueueTest.php index b4629ef4..2b225d8c 100644 --- a/tests/Unit/QueueTest.php +++ b/tests/Unit/QueueTest.php @@ -7,7 +7,6 @@ use Yiisoft\Queue\Cli\SignalLoop; use Yiisoft\Queue\JobStatus; use Yiisoft\Queue\Message\Message; -use Yiisoft\Queue\Stubs\StubAdapter; use Yiisoft\Queue\Tests\App\FakeAdapter; use Yiisoft\Queue\Tests\TestCase; use Yiisoft\Queue\Message\IdEnvelope; From df494f2e52aea5bd5af295f8069bd063ded02461 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 2 Apr 2026 16:59:47 +0300 Subject: [PATCH 3/3] fix --- config/di.php | 11 ----------- config/params.php | 4 ---- 2 files changed, 15 deletions(-) diff --git a/config/di.php b/config/di.php index 9cc29df1..475eabf6 100644 --- a/config/di.php +++ b/config/di.php @@ -17,22 +17,12 @@ use Yiisoft\Queue\Middleware\Push\MiddlewareFactoryPush; use Yiisoft\Queue\Middleware\Push\MiddlewareFactoryPushInterface; use Yiisoft\Queue\Middleware\Push\PushMiddlewareDispatcher; -use Yiisoft\Queue\Provider\AdapterFactoryQueueProvider; -use Yiisoft\Queue\Provider\QueueProviderInterface; -use Yiisoft\Queue\Queue; -use Yiisoft\Queue\QueueInterface; use Yiisoft\Queue\Worker\Worker as QueueWorker; use Yiisoft\Queue\Worker\WorkerInterface; /* @var array $params */ return [ - AdapterFactoryQueueProvider::class => [ - '__construct()' => [ - 'definitions' => $params['yiisoft/queue']['queues'], - ], - ], - QueueProviderInterface::class => AdapterFactoryQueueProvider::class, QueueWorker::class => [ 'class' => QueueWorker::class, '__construct()' => [$params['yiisoft/queue']['handlers']], @@ -43,7 +33,6 @@ ? $container->get(SignalLoop::class) : $container->get(SimpleLoop::class); }, - QueueInterface::class => Queue::class, MiddlewareFactoryPushInterface::class => MiddlewareFactoryPush::class, MiddlewareFactoryConsumeInterface::class => MiddlewareFactoryConsume::class, MiddlewareFactoryFailureInterface::class => MiddlewareFactoryFailure::class, diff --git a/config/params.php b/config/params.php index 90b8492f..c5023570 100644 --- a/config/params.php +++ b/config/params.php @@ -2,7 +2,6 @@ declare(strict_types=1); -use Yiisoft\Queue\Adapter\AdapterInterface; use Yiisoft\Queue\Command\ListenAllCommand; use Yiisoft\Queue\Command\ListenCommand; use Yiisoft\Queue\Command\RunCommand; @@ -22,9 +21,6 @@ ], 'yiisoft/queue' => [ 'handlers' => [], - 'queues' => [ - QueueProviderInterface::DEFAULT_QUEUE => AdapterInterface::class, - ], 'middlewares-push' => [], 'middlewares-consume' => [], 'middlewares-fail' => [],