From f98268066852a24951f6562285b042340f8d4fe5 Mon Sep 17 00:00:00 2001 From: viktorprogger Date: Sun, 8 Dec 2024 00:37:38 +0500 Subject: [PATCH] Bugfixes --- README.md | 5 - .../Provider/CompositeQueueProviderTest.php | 26 ++--- .../QueueFactoryQueueProviderTest.php | 94 ------------------- tests/Unit/QueueTest.php | 4 + 4 files changed, 18 insertions(+), 111 deletions(-) delete mode 100644 tests/Unit/Provider/QueueFactoryQueueProviderTest.php diff --git a/README.md b/README.md index 1d0ca5f2..4914175e 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,6 @@ $queue = $provider->get('channel-name'); Out of the box, there are four implementations of the `QueueProviderInterface`: - `AdapterFactoryQueueProvider` -- `QueueFactoryQueueProvider` - `PrototypeQueueProvider` - `CompositeQueueProvider` @@ -195,10 +194,6 @@ use Yiisoft\Queue\Adapter\SynchronousAdapter; For more information about a definition formats available see the [factory](https://github.com/yiisoft/factory) documentation. -### `QueueFactoryQueueProvider` - -Provider is similar to `AdapterFactoryQueueProvider`, but it uses definitions of channel-specific queues. - ### `PrototypeQueueProvider` Queue provider that only changes the channel name of the base queue. It can be useful when your queues used the same diff --git a/tests/Unit/Provider/CompositeQueueProviderTest.php b/tests/Unit/Provider/CompositeQueueProviderTest.php index 9d74e269..491017ee 100644 --- a/tests/Unit/Provider/CompositeQueueProviderTest.php +++ b/tests/Unit/Provider/CompositeQueueProviderTest.php @@ -4,9 +4,10 @@ namespace Yiisoft\Queue\Tests\Unit\Provider; +use Yiisoft\Queue\Provider\AdapterFactoryQueueProvider; use Yiisoft\Queue\Provider\ChannelNotFoundException; use Yiisoft\Queue\Provider\CompositeQueueProvider; -use Yiisoft\Queue\Provider\QueueFactoryQueueProvider; +use Yiisoft\Queue\Stubs\StubAdapter; use Yiisoft\Queue\Stubs\StubQueue; use Yiisoft\Queue\Tests\TestCase; @@ -14,13 +15,16 @@ final class CompositeQueueProviderTest extends TestCase { public function testBase(): void { + $queue = new StubQueue('channel'); $provider = new CompositeQueueProvider( - new QueueFactoryQueueProvider([ - 'channel1' => new StubQueue('channel1'), - ]), - new QueueFactoryQueueProvider([ - 'channel2' => new StubQueue('channel2'), - ]), + new AdapterFactoryQueueProvider( + $queue, + ['channel1' => new StubAdapter()], + ), + new AdapterFactoryQueueProvider( + $queue, + ['channel2' => new StubAdapter()], + ), ); $this->assertTrue($provider->has('channel1')); @@ -34,13 +38,11 @@ public function testBase(): void public function testNotFound(): void { $provider = new CompositeQueueProvider( - new QueueFactoryQueueProvider([ - 'channel1' => new StubQueue(), - ]), + new AdapterFactoryQueueProvider(new StubQueue('channel'), ['channel1' => new StubAdapter()]), ); $this->expectException(ChannelNotFoundException::class); - $this->expectExceptionMessage('Channel "not-exist" not found.'); - $provider->get('not-exist'); + $this->expectExceptionMessage('Channel "not-exists" not found.'); + $provider->get('not-exists'); } } diff --git a/tests/Unit/Provider/QueueFactoryQueueProviderTest.php b/tests/Unit/Provider/QueueFactoryQueueProviderTest.php deleted file mode 100644 index 6a569d35..00000000 --- a/tests/Unit/Provider/QueueFactoryQueueProviderTest.php +++ /dev/null @@ -1,94 +0,0 @@ - StubQueue::class, - ], - ); - - $queue = $provider->get('channel1'); - - $this->assertInstanceOf(StubQueue::class, $queue); - $this->assertSame('channel1', $queue->getChannelName()); - $this->assertTrue($provider->has('channel1')); - $this->assertFalse($provider->has('not-exist-channel')); - } - - public function testGetTwice(): void - { - $provider = new QueueFactoryQueueProvider( - [ - 'channel1' => StubQueue::class, - ], - ); - - $queue1 = $provider->get('channel1'); - $queue2 = $provider->get('channel1'); - - $this->assertSame($queue1, $queue2); - } - - public function testGetNotExistChannel(): void - { - $provider = new QueueFactoryQueueProvider( - [ - 'channel1' => StubQueue::class, - ], - ); - - $this->expectException(ChannelNotFoundException::class); - $this->expectExceptionMessage('Channel "not-exist-channel" not found.'); - $provider->get('not-exist-channel'); - } - - public function testInvalidQueueConfig(): void - { - $definitions = [ - 'channel1' => [ - 'class' => StubQueue::class, - '__construct()' => 'hello', - ], - ]; - - $this->expectException(InvalidQueueConfigException::class); - $this->expectExceptionMessage( - 'Invalid definition: incorrect constructor arguments. Expected array, got string.' - ); - new QueueFactoryQueueProvider($definitions); - } - - public function testInvalidQueueConfigOnGet(): void - { - $provider = new QueueFactoryQueueProvider([ - 'channel1' => StubLoop::class, - ]); - - $this->expectException(InvalidQueueConfigException::class); - $this->expectExceptionMessage( - sprintf( - 'Queue must implement "%s". For channel "channel1" got "%s" instead.', - QueueInterface::class, - StubLoop::class, - ) - ); - $provider->get('channel1'); - } -} diff --git a/tests/Unit/QueueTest.php b/tests/Unit/QueueTest.php index 7a477e66..24a0155f 100644 --- a/tests/Unit/QueueTest.php +++ b/tests/Unit/QueueTest.php @@ -130,6 +130,10 @@ public function testAdapterNotConfiguredExceptionForRun(): void public function testRunWithSignalLoop(): void { + if (!extension_loaded('pcntl')) { + $this->markTestSkipped("This rest requires PCNTL extension"); + } + $this->loop = new SignalLoop(); $queue = $this ->getQueue()