From aaad79f2c7dd0a918de8b43dfe6ee2f117d6da94 Mon Sep 17 00:00:00 2001 From: VojtaB Date: Thu, 12 Dec 2024 19:47:42 +0100 Subject: [PATCH 01/10] load timeouts from laravel config --- README.md | 27 ++++++++++++++++++++++++++ src/Queue/Connection/ConfigFactory.php | 24 +++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/README.md b/README.md index adb7b2e9..30a10df9 100644 --- a/README.md +++ b/README.md @@ -529,6 +529,33 @@ Available protocols : `tcp`, `ssl`, `tls` ], ``` +### Network Timeouts + +For network timeouts configuration you can use option parameters. +All float values are in seconds and zero value can mean infinite timeout. +Example contains default values. + +```php +'connections' => [ + // ... + + 'rabbitmq' => [ + // ... + + 'options' => [ + // ... + + 'connection_timeout' => 3.0, + 'read_timeout' => 3.0, + 'write_timeout' => 3.0, + 'channel_rpc_timeout' => 0.0, + ], + ], + + // ... +], +``` + ### Octane support Starting with 13.3.0, this package supports [Laravel Octane](https://laravel.com/docs/octane) out of the box. diff --git a/src/Queue/Connection/ConfigFactory.php b/src/Queue/Connection/ConfigFactory.php index 7783b9cd..8e013efd 100644 --- a/src/Queue/Connection/ConfigFactory.php +++ b/src/Queue/Connection/ConfigFactory.php @@ -38,6 +38,7 @@ public static function make(array $config = []): AMQPConnectionConfig self::getHostFromConfig($connectionConfig, $config); self::getHeartbeatFromConfig($connectionConfig, $config); self::getNetworkProtocolFromConfig($connectionConfig, $config); + self::getTimeoutsFromConfig($connectionConfig, $config); }); } @@ -99,4 +100,27 @@ protected static function getNetworkProtocolFromConfig(AMQPConnectionConfig $con $connectionConfig->setNetworkProtocol($networkProtocol); } } + + protected static function getTimeoutsFromConfig(AMQPConnectionConfig $connectionConfig, array $config): void + { + $connectionTimeout = Arr::get($config, self::CONFIG_OPTIONS.'.connection_timeout'); + if (is_numeric($connectionTimeout) && floatval($connectionTimeout) >= 0) { + $connectionConfig->setConnectionTimeout((float) $connectionTimeout); + } + + $readTimeout = Arr::get($config, self::CONFIG_OPTIONS.'.read_timeout'); + if (is_numeric($readTimeout) && floatval($readTimeout) >= 0) { + $connectionConfig->setReadTimeout((float) $readTimeout); + } + + $writeTimeout = Arr::get($config, self::CONFIG_OPTIONS.'.write_timeout'); + if (is_numeric($writeTimeout) && floatval($writeTimeout) >= 0) { + $connectionConfig->setWriteTimeout((float) $writeTimeout); + } + + $chanelRpcTimeout = Arr::get($config, self::CONFIG_OPTIONS.'.channel_rpc_timeout'); + if (is_numeric($chanelRpcTimeout) && floatval($chanelRpcTimeout) >= 0) { + $connectionConfig->setChannelRPCTimeout((float) $chanelRpcTimeout); + } + } } From c00a8cce370a1525cacfff2b7c5e11d666943e5a Mon Sep 17 00:00:00 2001 From: Sergey Tarasenko Date: Thu, 23 Jan 2025 00:19:27 +0300 Subject: [PATCH 02/10] pint fixes --- pint.json | 4 ++-- src/Horizon/RabbitMQQueue.php | 2 +- src/Queue/Connection/ConfigFactory.php | 2 +- src/Queue/QueueConfigFactory.php | 2 +- src/Queue/RabbitMQQueue.php | 14 +++++++------- tests/Feature/QueueTest.php | 6 +++--- tests/Feature/SslQueueTest.php | 2 +- tests/Feature/TestCase.php | 20 ++++++++++---------- tests/Functional/RabbitMQQueueTest.php | 2 +- tests/TestCase.php | 2 +- 10 files changed, 28 insertions(+), 28 deletions(-) diff --git a/pint.json b/pint.json index 751c2203..029010c0 100644 --- a/pint.json +++ b/pint.json @@ -1,8 +1,8 @@ { "preset": "laravel", "rules": { - "nullable_type_declaration_for_default_null_value": { - "use_nullable_type_declaration": false + "php_unit_method_casing": { + "case": "camel_case" } } } diff --git a/src/Horizon/RabbitMQQueue.php b/src/Horizon/RabbitMQQueue.php index 894cc24b..e2ca400d 100644 --- a/src/Horizon/RabbitMQQueue.php +++ b/src/Horizon/RabbitMQQueue.php @@ -26,7 +26,7 @@ class RabbitMQQueue extends BaseRabbitMQQueue * * @throws AMQPProtocolChannelException */ - public function readyNow(string $queue = null): int + public function readyNow(?string $queue = null): int { return $this->size($queue); } diff --git a/src/Queue/Connection/ConfigFactory.php b/src/Queue/Connection/ConfigFactory.php index 7783b9cd..f3ecd409 100644 --- a/src/Queue/Connection/ConfigFactory.php +++ b/src/Queue/Connection/ConfigFactory.php @@ -16,7 +16,7 @@ class ConfigFactory */ public static function make(array $config = []): AMQPConnectionConfig { - return tap(new AMQPConnectionConfig(), function (AMQPConnectionConfig $connectionConfig) use ($config) { + return tap(new AMQPConnectionConfig, function (AMQPConnectionConfig $connectionConfig) use ($config) { // Set the connection to a Lazy by default $connectionConfig->setIsLazy(! in_array( Arr::get($config, 'lazy') ?? true, diff --git a/src/Queue/QueueConfigFactory.php b/src/Queue/QueueConfigFactory.php index 87fc2fac..6f2befc5 100644 --- a/src/Queue/QueueConfigFactory.php +++ b/src/Queue/QueueConfigFactory.php @@ -13,7 +13,7 @@ class QueueConfigFactory */ public static function make(array $config = []): QueueConfig { - return tap(new QueueConfig(), function (QueueConfig $queueConfig) use ($config) { + return tap(new QueueConfig, function (QueueConfig $queueConfig) use ($config) { if (! empty($queue = Arr::get($config, 'queue'))) { $queueConfig->setQueue($queue); } diff --git a/src/Queue/RabbitMQQueue.php b/src/Queue/RabbitMQQueue.php index 957620ef..fadedce5 100644 --- a/src/Queue/RabbitMQQueue.php +++ b/src/Queue/RabbitMQQueue.php @@ -204,7 +204,7 @@ protected function publishBatch($jobs, $data = '', $queue = null): void /** * @throws AMQPProtocolChannelException */ - public function bulkRaw(string $payload, string $queue = null, array $options = []): int|string|null + public function bulkRaw(string $payload, ?string $queue = null, array $options = []): int|string|null { [$destination, $exchange, $exchangeType, $attempts] = $this->publishProperties($queue, $options); @@ -397,7 +397,7 @@ public function deleteExchange(string $name, bool $unused = false): void * * @throws AMQPProtocolChannelException */ - public function isQueueExists(string $name = null): bool + public function isQueueExists(?string $name = null): bool { $queueName = $this->getQueue($name); @@ -484,7 +484,7 @@ public function bindQueue(string $queue, string $exchange, string $routingKey = /** * Purge the queue of messages. */ - public function purge(string $queue = null): void + public function purge(?string $queue = null): void { // create a temporary channel, so the main channel will not be closed on exception $channel = $this->createChannel(); @@ -637,7 +637,7 @@ protected function getDelayQueueArguments(string $destination, int $ttl): array /** * Get the exchange name, or empty string; as default value. */ - protected function getExchange(string $exchange = null): string + protected function getExchange(?string $exchange = null): string { return $exchange ?? $this->getConfig()->getExchange(); } @@ -654,7 +654,7 @@ protected function getRoutingKey(string $destination): string /** * Get the exchangeType, or AMQPExchangeType::DIRECT as default. */ - protected function getExchangeType(string $type = null): string + protected function getExchangeType(?string $type = null): string { $constant = AMQPExchangeType::class.'::'.Str::upper($type ?: $this->getConfig()->getExchangeType()); @@ -664,7 +664,7 @@ protected function getExchangeType(string $type = null): string /** * Get the exchange for failed messages. */ - protected function getFailedExchange(string $exchange = null): string + protected function getFailedExchange(?string $exchange = null): string { return $exchange ?? $this->getConfig()->getFailedExchange(); } @@ -699,7 +699,7 @@ protected function isQueueDeclared(string $name): bool * * @throws AMQPProtocolChannelException */ - protected function declareDestination(string $destination, string $exchange = null, string $exchangeType = AMQPExchangeType::DIRECT): void + protected function declareDestination(string $destination, ?string $exchange = null, string $exchangeType = AMQPExchangeType::DIRECT): void { // When an exchange is provided and no exchange is present in RabbitMQ, create an exchange. if ($exchange && ! $this->isExchangeExists($exchange)) { diff --git a/tests/Feature/QueueTest.php b/tests/Feature/QueueTest.php index 5ecfb978..ee324c9a 100644 --- a/tests/Feature/QueueTest.php +++ b/tests/Feature/QueueTest.php @@ -10,7 +10,7 @@ class QueueTest extends TestCase { - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -29,7 +29,7 @@ public function testWithoutReconnect(): void { $queue = $this->connection('rabbitmq'); - $queue->push(new TestJob()); + $queue->push(new TestJob); sleep(1); $this->assertSame(1, $queue->size()); @@ -38,6 +38,6 @@ public function testWithoutReconnect(): void $this->assertFalse($queue->getConnection()->isConnected()); $this->expectException(AMQPChannelClosedException::class); - $queue->push(new TestJob()); + $queue->push(new TestJob); } } diff --git a/tests/Feature/SslQueueTest.php b/tests/Feature/SslQueueTest.php index e9c460ea..02181c96 100644 --- a/tests/Feature/SslQueueTest.php +++ b/tests/Feature/SslQueueTest.php @@ -6,7 +6,7 @@ class SslQueueTest extends TestCase { - public function setUp(): void + protected function setUp(): void { $this->markTestSkipped(); } diff --git a/tests/Feature/TestCase.php b/tests/Feature/TestCase.php index 16fd5faa..5afda85d 100644 --- a/tests/Feature/TestCase.php +++ b/tests/Feature/TestCase.php @@ -17,7 +17,7 @@ abstract class TestCase extends BaseTestCase /** * @throws AMQPProtocolChannelException */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -70,7 +70,7 @@ public function testPushRaw(): void public function testPush(): void { - Queue::push(new TestJob()); + Queue::push(new TestJob); sleep(1); @@ -154,7 +154,7 @@ public function testLaterRaw(): void public function testLater(): void { - Queue::later(3, new TestJob()); + Queue::later(3, new TestJob); sleep(1); @@ -197,7 +197,7 @@ public function testBulk(): void public function testPushEncrypted(): void { - Queue::push(new TestEncryptedJob()); + Queue::push(new TestEncryptedJob); sleep(1); @@ -251,7 +251,7 @@ public function testPushEncryptedAfterCommit(): void public function testEncryptedLater(): void { - Queue::later(3, new TestEncryptedJob()); + Queue::later(3, new TestEncryptedJob); sleep(1); @@ -320,7 +320,7 @@ public function testReleaseRaw(): void public function testRelease(): void { - Queue::push(new TestJob()); + Queue::push(new TestJob); sleep(1); @@ -377,7 +377,7 @@ public function testReleaseWithDelayRaw(): void public function testReleaseInThePast(): void { - Queue::push(new TestJob()); + Queue::push(new TestJob); $job = Queue::pop(); $job->release(-3); @@ -392,7 +392,7 @@ public function testReleaseInThePast(): void public function testReleaseAndReleaseWithDelayAttempts(): void { - Queue::push(new TestJob()); + Queue::push(new TestJob); sleep(1); @@ -419,7 +419,7 @@ public function testReleaseAndReleaseWithDelayAttempts(): void public function testDelete(): void { - Queue::push(new TestJob()); + Queue::push(new TestJob); $job = Queue::pop(); @@ -433,7 +433,7 @@ public function testDelete(): void public function testFailed(): void { - Queue::push(new TestJob()); + Queue::push(new TestJob); $job = Queue::pop(); diff --git a/tests/Functional/RabbitMQQueueTest.php b/tests/Functional/RabbitMQQueueTest.php index 7a106a08..1c5d94fb 100644 --- a/tests/Functional/RabbitMQQueueTest.php +++ b/tests/Functional/RabbitMQQueueTest.php @@ -87,7 +87,7 @@ public function testConfigExchangeType(): void $queue = $this->connection('rabbitmq-with-options-null'); $this->assertSame(AMQPExchangeType::DIRECT, $this->callMethod($queue, 'getExchangeType')); - //testing an unkown type with a default + // testing an unkown type with a default $this->callProperty($queue, 'config')->setExchangeType('unknown'); $this->assertSame(AMQPExchangeType::DIRECT, $this->callMethod($queue, 'getExchangeType')); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 7d50fa67..f1ffb8d4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -50,7 +50,7 @@ protected function getEnvironmentSetUp($app): void ]); } - protected function connection(string $name = null): RabbitMQQueue + protected function connection(?string $name = null): RabbitMQQueue { return Queue::connection($name); } From 4765c204d3c86aef9d6e1eda75a413c38efdad36 Mon Sep 17 00:00:00 2001 From: Samuel Fontebasso Date: Sun, 20 Apr 2025 01:45:50 -0300 Subject: [PATCH 03/10] style: fix formatting issues to pass lint/tests --- src/Queue/Connection/ConfigFactory.php | 2 +- src/Queue/QueueConfigFactory.php | 2 +- tests/Feature/ConnectorTest.php | 8 ++-- tests/Feature/QueueTest.php | 10 ++--- tests/Feature/SslQueueTest.php | 4 +- tests/Feature/TestCase.php | 58 +++++++++++++------------- tests/Functional/RabbitMQQueueTest.php | 30 ++++++------- tests/Functional/TestCase.php | 4 +- 8 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/Queue/Connection/ConfigFactory.php b/src/Queue/Connection/ConfigFactory.php index 7783b9cd..f3ecd409 100644 --- a/src/Queue/Connection/ConfigFactory.php +++ b/src/Queue/Connection/ConfigFactory.php @@ -16,7 +16,7 @@ class ConfigFactory */ public static function make(array $config = []): AMQPConnectionConfig { - return tap(new AMQPConnectionConfig(), function (AMQPConnectionConfig $connectionConfig) use ($config) { + return tap(new AMQPConnectionConfig, function (AMQPConnectionConfig $connectionConfig) use ($config) { // Set the connection to a Lazy by default $connectionConfig->setIsLazy(! in_array( Arr::get($config, 'lazy') ?? true, diff --git a/src/Queue/QueueConfigFactory.php b/src/Queue/QueueConfigFactory.php index 87fc2fac..6f2befc5 100644 --- a/src/Queue/QueueConfigFactory.php +++ b/src/Queue/QueueConfigFactory.php @@ -13,7 +13,7 @@ class QueueConfigFactory */ public static function make(array $config = []): QueueConfig { - return tap(new QueueConfig(), function (QueueConfig $queueConfig) use ($config) { + return tap(new QueueConfig, function (QueueConfig $queueConfig) use ($config) { if (! empty($queue = Arr::get($config, 'queue'))) { $queueConfig->setQueue($queue); } diff --git a/tests/Feature/ConnectorTest.php b/tests/Feature/ConnectorTest.php index 91660ad2..f4e330c3 100644 --- a/tests/Feature/ConnectorTest.php +++ b/tests/Feature/ConnectorTest.php @@ -12,7 +12,7 @@ class ConnectorTest extends \VladimirYuldashev\LaravelQueueRabbitMQ\Tests\TestCase { - public function testLazyConnection(): void + public function test_lazy_connection(): void { $this->app['config']->set('queue.connections.rabbitmq', [ 'driver' => 'rabbitmq', @@ -55,7 +55,7 @@ public function testLazyConnection(): void $this->assertTrue($connection->getConnection()->isConnected()); } - public function testLazyStreamConnection(): void + public function test_lazy_stream_connection(): void { $this->app['config']->set('queue.connections.rabbitmq', [ 'driver' => 'rabbitmq', @@ -98,7 +98,7 @@ public function testLazyStreamConnection(): void $this->assertTrue($connection->getConnection()->isConnected()); } - public function testSslConnection(): void + public function test_ssl_connection(): void { $this->markTestSkipped(); @@ -142,7 +142,7 @@ public function testSslConnection(): void } // Test to validate ssl connection params - public function testNoVerificationSslConnection(): void + public function test_no_verification_ssl_connection(): void { $this->app['config']->set('queue.connections.rabbitmq', [ 'driver' => 'rabbitmq', diff --git a/tests/Feature/QueueTest.php b/tests/Feature/QueueTest.php index 5ecfb978..609a48d8 100644 --- a/tests/Feature/QueueTest.php +++ b/tests/Feature/QueueTest.php @@ -10,7 +10,7 @@ class QueueTest extends TestCase { - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -20,16 +20,16 @@ public function setUp(): void ]); } - public function testConnection(): void + public function test_connection(): void { $this->assertInstanceOf(AMQPStreamConnection::class, $this->connection()->getChannel()->getConnection()); } - public function testWithoutReconnect(): void + public function test_without_reconnect(): void { $queue = $this->connection('rabbitmq'); - $queue->push(new TestJob()); + $queue->push(new TestJob); sleep(1); $this->assertSame(1, $queue->size()); @@ -38,6 +38,6 @@ public function testWithoutReconnect(): void $this->assertFalse($queue->getConnection()->isConnected()); $this->expectException(AMQPChannelClosedException::class); - $queue->push(new TestJob()); + $queue->push(new TestJob); } } diff --git a/tests/Feature/SslQueueTest.php b/tests/Feature/SslQueueTest.php index e9c460ea..53cf5d38 100644 --- a/tests/Feature/SslQueueTest.php +++ b/tests/Feature/SslQueueTest.php @@ -6,7 +6,7 @@ class SslQueueTest extends TestCase { - public function setUp(): void + protected function setUp(): void { $this->markTestSkipped(); } @@ -43,7 +43,7 @@ protected function getEnvironmentSetUp($app): void ]); } - public function testConnection(): void + public function test_connection(): void { $this->assertInstanceOf(AMQPSSLConnection::class, $this->connection()->getChannel()->getConnection()); } diff --git a/tests/Feature/TestCase.php b/tests/Feature/TestCase.php index 16fd5faa..7d0fab9a 100644 --- a/tests/Feature/TestCase.php +++ b/tests/Feature/TestCase.php @@ -17,7 +17,7 @@ abstract class TestCase extends BaseTestCase /** * @throws AMQPProtocolChannelException */ - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -40,17 +40,17 @@ protected function tearDown(): void parent::tearDown(); } - public function testSizeDoesNotThrowExceptionOnUnknownQueue(): void + public function test_size_does_not_throw_exception_on_unknown_queue(): void { $this->assertEmpty(0, Queue::size(Str::random())); } - public function testPopNothing(): void + public function test_pop_nothing(): void { $this->assertNull(Queue::pop('foo')); } - public function testPushRaw(): void + public function test_push_raw(): void { Queue::pushRaw($payload = Str::random()); @@ -68,9 +68,9 @@ public function testPushRaw(): void $this->assertSame(0, Queue::size()); } - public function testPush(): void + public function test_push(): void { - Queue::push(new TestJob()); + Queue::push(new TestJob); sleep(1); @@ -95,7 +95,7 @@ public function testPush(): void $this->assertSame(0, Queue::size()); } - public function testPushAfterCommit(): void + public function test_push_after_commit(): void { $transaction = new DatabaseTransactionsManager; @@ -122,7 +122,7 @@ public function testPushAfterCommit(): void $this->assertSame(0, Queue::size()); } - public function testLaterRaw(): void + public function test_later_raw(): void { $payload = Str::random(); $data = [Str::random() => Str::random()]; @@ -152,9 +152,9 @@ public function testLaterRaw(): void $this->assertSame(0, Queue::size()); } - public function testLater(): void + public function test_later(): void { - Queue::later(3, new TestJob()); + Queue::later(3, new TestJob); sleep(1); @@ -179,7 +179,7 @@ public function testLater(): void $this->assertSame(0, Queue::size()); } - public function testBulk(): void + public function test_bulk(): void { $count = 100; $jobs = []; @@ -195,9 +195,9 @@ public function testBulk(): void $this->assertSame($count, Queue::size()); } - public function testPushEncrypted(): void + public function test_push_encrypted(): void { - Queue::push(new TestEncryptedJob()); + Queue::push(new TestEncryptedJob); sleep(1); @@ -222,7 +222,7 @@ public function testPushEncrypted(): void $this->assertSame(0, Queue::size()); } - public function testPushEncryptedAfterCommit(): void + public function test_push_encrypted_after_commit(): void { $transaction = new DatabaseTransactionsManager; @@ -249,9 +249,9 @@ public function testPushEncryptedAfterCommit(): void $this->assertSame(0, Queue::size()); } - public function testEncryptedLater(): void + public function test_encrypted_later(): void { - Queue::later(3, new TestEncryptedJob()); + Queue::later(3, new TestEncryptedJob); sleep(1); @@ -276,7 +276,7 @@ public function testEncryptedLater(): void $this->assertSame(0, Queue::size()); } - public function testEncryptedBulk(): void + public function test_encrypted_bulk(): void { $count = 100; $jobs = []; @@ -292,7 +292,7 @@ public function testEncryptedBulk(): void $this->assertSame($count, Queue::size()); } - public function testReleaseRaw(): void + public function test_release_raw(): void { Queue::pushRaw($payload = Str::random()); @@ -318,9 +318,9 @@ public function testReleaseRaw(): void $this->assertSame(0, Queue::size()); } - public function testRelease(): void + public function test_release(): void { - Queue::push(new TestJob()); + Queue::push(new TestJob); sleep(1); @@ -344,7 +344,7 @@ public function testRelease(): void $this->assertSame(0, Queue::size()); } - public function testReleaseWithDelayRaw(): void + public function test_release_with_delay_raw(): void { Queue::pushRaw($payload = Str::random()); @@ -375,9 +375,9 @@ public function testReleaseWithDelayRaw(): void $this->assertSame(0, Queue::size()); } - public function testReleaseInThePast(): void + public function test_release_in_the_past(): void { - Queue::push(new TestJob()); + Queue::push(new TestJob); $job = Queue::pop(); $job->release(-3); @@ -390,9 +390,9 @@ public function testReleaseInThePast(): void $this->assertSame(0, Queue::size()); } - public function testReleaseAndReleaseWithDelayAttempts(): void + public function test_release_and_release_with_delay_attempts(): void { - Queue::push(new TestJob()); + Queue::push(new TestJob); sleep(1); @@ -417,9 +417,9 @@ public function testReleaseAndReleaseWithDelayAttempts(): void $this->assertSame(0, Queue::size()); } - public function testDelete(): void + public function test_delete(): void { - Queue::push(new TestJob()); + Queue::push(new TestJob); $job = Queue::pop(); @@ -431,9 +431,9 @@ public function testDelete(): void $this->assertNull(Queue::pop()); } - public function testFailed(): void + public function test_failed(): void { - Queue::push(new TestJob()); + Queue::push(new TestJob); $job = Queue::pop(); diff --git a/tests/Functional/RabbitMQQueueTest.php b/tests/Functional/RabbitMQQueueTest.php index 7a106a08..21a2e1d4 100644 --- a/tests/Functional/RabbitMQQueueTest.php +++ b/tests/Functional/RabbitMQQueueTest.php @@ -9,7 +9,7 @@ class RabbitMQQueueTest extends BaseTestCase { - public function testConnection(): void + public function test_connection(): void { $queue = $this->connection(); $this->assertInstanceOf(RabbitMQQueue::class, $queue); @@ -21,7 +21,7 @@ public function testConnection(): void $this->assertInstanceOf(RabbitMQQueue::class, $queue); } - public function testConfigRerouteFailed(): void + public function test_config_reroute_failed(): void { $queue = $this->connection(); $this->assertFalse($this->callProperty($queue, 'config')->isRerouteFailed()); @@ -36,7 +36,7 @@ public function testConfigRerouteFailed(): void $this->assertFalse($this->callProperty($queue, 'config')->isRerouteFailed()); } - public function testConfigPrioritizeDelayed(): void + public function test_config_prioritize_delayed(): void { $queue = $this->connection(); $this->assertFalse($this->callProperty($queue, 'config')->isPrioritizeDelayed()); @@ -51,7 +51,7 @@ public function testConfigPrioritizeDelayed(): void $this->assertFalse($this->callProperty($queue, 'config')->isPrioritizeDelayed()); } - public function testQueueMaxPriority(): void + public function test_queue_max_priority(): void { $queue = $this->connection(); $this->assertIsInt($this->callProperty($queue, 'config')->getQueueMaxPriority()); @@ -70,7 +70,7 @@ public function testQueueMaxPriority(): void $this->assertSame(2, $this->callProperty($queue, 'config')->getQueueMaxPriority()); } - public function testConfigExchangeType(): void + public function test_config_exchange_type(): void { $queue = $this->connection(); $this->assertSame(AMQPExchangeType::DIRECT, $this->callMethod($queue, 'getExchangeType')); @@ -87,12 +87,12 @@ public function testConfigExchangeType(): void $queue = $this->connection('rabbitmq-with-options-null'); $this->assertSame(AMQPExchangeType::DIRECT, $this->callMethod($queue, 'getExchangeType')); - //testing an unkown type with a default + // testing an unkown type with a default $this->callProperty($queue, 'config')->setExchangeType('unknown'); $this->assertSame(AMQPExchangeType::DIRECT, $this->callMethod($queue, 'getExchangeType')); } - public function testExchange(): void + public function test_exchange(): void { $queue = $this->connection(); $this->assertSame('test', $this->callMethod($queue, 'getExchange', ['test'])); @@ -119,7 +119,7 @@ public function testExchange(): void $this->assertSame('', $this->callMethod($queue, 'getExchange', [''])); } - public function testFailedExchange(): void + public function test_failed_exchange(): void { $queue = $this->connection(); $this->assertSame('test', $this->callMethod($queue, 'getFailedExchange', ['test'])); @@ -146,7 +146,7 @@ public function testFailedExchange(): void $this->assertSame('', $this->callMethod($queue, 'getFailedExchange', [''])); } - public function testRoutingKey(): void + public function test_routing_key(): void { $queue = $this->connection(); $this->assertSame('test', $this->callMethod($queue, 'getRoutingKey', ['test'])); @@ -165,7 +165,7 @@ public function testRoutingKey(): void $this->assertSame('an.alternate.routing-key', $this->callMethod($queue, 'getRoutingKey', ['test'])); } - public function testFailedRoutingKey(): void + public function test_failed_routing_key(): void { $queue = $this->connection(); $this->assertSame('test.failed', $this->callMethod($queue, 'getFailedRoutingKey', ['test'])); @@ -184,7 +184,7 @@ public function testFailedRoutingKey(): void $this->assertSame('an.alternate.routing-key', $this->callMethod($queue, 'getFailedRoutingKey', ['test'])); } - public function testConfigQuorum(): void + public function test_config_quorum(): void { $queue = $this->connection(); $this->assertFalse($this->callProperty($queue, 'config')->isQuorum()); @@ -202,7 +202,7 @@ public function testConfigQuorum(): void $this->assertTrue($this->callProperty($queue, 'config')->isQuorum()); } - public function testDeclareDeleteExchange(): void + public function test_declare_delete_exchange(): void { $queue = $this->connection(); @@ -217,7 +217,7 @@ public function testDeclareDeleteExchange(): void $this->assertFalse($queue->isExchangeExists($name)); } - public function testDeclareDeleteQueue(): void + public function test_declare_delete_queue(): void { $queue = $this->connection(); @@ -232,7 +232,7 @@ public function testDeclareDeleteQueue(): void $this->assertFalse($queue->isQueueExists($name)); } - public function testQueueArguments(): void + public function test_queue_arguments(): void { $name = Str::random(); @@ -272,7 +272,7 @@ public function testQueueArguments(): void $this->assertEquals(array_values($expected), array_values($actual)); } - public function testDelayQueueArguments(): void + public function test_delay_queue_arguments(): void { $name = Str::random(); $ttl = 12000; diff --git a/tests/Functional/TestCase.php b/tests/Functional/TestCase.php index 8b843561..b21aeaf8 100644 --- a/tests/Functional/TestCase.php +++ b/tests/Functional/TestCase.php @@ -236,7 +236,7 @@ protected function callProperty($object, string $property): mixed return $property->getValue($object); } - public function testConnectChannel(): void + public function test_connect_channel(): void { $queue = $this->connection(); $this->assertFalse($queue->getConnection()->isConnected()); @@ -248,7 +248,7 @@ public function testConnectChannel(): void $this->assertTrue($channel->is_open()); } - public function testReconnect(): void + public function test_reconnect(): void { $queue = $this->connection(); $this->assertFalse($queue->getConnection()->isConnected()); From 9c5fa17a0aa0d175d4849703553997b6edb72613 Mon Sep 17 00:00:00 2001 From: Samuel Fontebasso Date: Sun, 20 Apr 2025 02:01:38 -0300 Subject: [PATCH 04/10] fix: remove manual docker-compose v1 install to prevent CI failure on ubuntu-latest --- .github/workflows/tests.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fccb0608..0da38f44 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,15 +33,8 @@ jobs: extensions: dom, curl, libxml, mbstring, zip coverage: none - - name: Set up Docker - run: | - sudo rm /usr/local/bin/docker-compose - curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > docker-compose - chmod +x docker-compose - sudo mv docker-compose /usr/local/bin - - name: Start Docker container - run: docker-compose up -d rabbitmq + run: docker compose up -d rabbitmq - name: Install dependencies run: composer update --with='laravel/framework:${{matrix.laravel}}' --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress From e69dd13ebfde40ae6993ee977e67ca22bd3e9609 Mon Sep 17 00:00:00 2001 From: Samuel Fontebasso Date: Mon, 21 Apr 2025 15:28:51 -0300 Subject: [PATCH 05/10] feat: add Laravel 12 support and fix test connection by disabling SSL verify_peer --- .github/workflows/tests.yml | 4 +++- composer.json | 6 +++--- tests/TestCase.php | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0da38f44..d0588c10 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,10 +15,12 @@ jobs: matrix: php: ['8.1', '8.2', '8.3'] stability: ['prefer-lowest', 'prefer-stable'] - laravel: ['^10.0', '^11.0'] + laravel: ['^10.0', '^11.0', '^12.0'] exclude: - php: '8.1' laravel: '^11.0' + - php: '8.1' + laravel: '^12.0' name: 'PHP ${{ matrix.php }} - Laravel: ${{matrix.laravel}} - ${{ matrix.stability }}' diff --git a/composer.json b/composer.json index 1a91d725..caf8a0fc 100644 --- a/composer.json +++ b/composer.json @@ -11,16 +11,16 @@ "require": { "php": "^8.0", "ext-json": "*", - "illuminate/queue": "^10.0|^11.0", + "illuminate/queue": "^10.0|^11.0|^12.0", "php-amqplib/php-amqplib": "^v3.6" }, "require-dev": { "phpunit/phpunit": "^10.0|^11.0", "mockery/mockery": "^1.0", "laravel/horizon": "^5.0", - "orchestra/testbench": "^7.0|^8.0|^9.0", + "orchestra/testbench": "^7.0|^8.0|^9.0|^10.0", "laravel/pint": "^1.2", - "laravel/framework": "^9.0|^10.0|^11.0" + "laravel/framework": "^9.0|^10.0|^11.0|^12.0" }, "autoload": { "psr-4": { diff --git a/tests/TestCase.php b/tests/TestCase.php index 7d50fa67..f3f0705d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -40,7 +40,7 @@ protected function getEnvironmentSetUp($app): void 'cafile' => null, 'local_cert' => null, 'local_key' => null, - 'verify_peer' => true, + 'verify_peer' => false, 'passphrase' => null, ], ], From 6faa83ac6554a0b8340756c7ffee0f7b68741cd7 Mon Sep 17 00:00:00 2001 From: Samuel Fontebasso Date: Mon, 21 Apr 2025 17:02:52 -0300 Subject: [PATCH 06/10] feat: add --json flag to rabbitmq:consume and align option order with WorkCommand --- src/Console/ConsumeCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Console/ConsumeCommand.php b/src/Console/ConsumeCommand.php index 50aab1d4..4072132a 100644 --- a/src/Console/ConsumeCommand.php +++ b/src/Console/ConsumeCommand.php @@ -21,9 +21,10 @@ class ConsumeCommand extends WorkCommand {--force : Force the worker to run even in maintenance mode} {--memory=128 : The memory limit in megabytes} {--sleep=3 : Number of seconds to sleep when no job is available} + {--rest=0 : Number of seconds to rest between jobs} {--timeout=60 : The number of seconds a child process can run} {--tries=1 : Number of times to attempt a job before logging it failed} - {--rest=0 : Number of seconds to rest between jobs} + {--json : Output the queue worker information as JSON} {--max-priority=} {--consumer-tag} From 4717111a1e3f7e70cc0e43e7752a5720fdd86207 Mon Sep 17 00:00:00 2001 From: Samuel Fontebasso Date: Wed, 30 Apr 2025 21:58:45 -0300 Subject: [PATCH 07/10] chore(ci): add PHP 8.4 to test matrix --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d0588c10..4aad6d20 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: true matrix: - php: ['8.1', '8.2', '8.3'] + php: ['8.1', '8.2', '8.3', '8.4'] stability: ['prefer-lowest', 'prefer-stable'] laravel: ['^10.0', '^11.0', '^12.0'] exclude: From e82de4ceef0ab3ddf5f4aaaa2816ea4c2dc49ef5 Mon Sep 17 00:00:00 2001 From: Samuel Fontebasso Date: Wed, 30 Apr 2025 22:24:44 -0300 Subject: [PATCH 08/10] style: rename PHPUnit test methods to camelCase --- pint.json | 2 +- tests/Feature/ConnectorTest.php | 8 +++--- tests/Feature/QueueTest.php | 4 +-- tests/Feature/SslQueueTest.php | 2 +- tests/Feature/TestCase.php | 38 +++++++++++++------------- tests/Functional/RabbitMQQueueTest.php | 28 +++++++++---------- tests/Functional/TestCase.php | 4 +-- 7 files changed, 43 insertions(+), 43 deletions(-) diff --git a/pint.json b/pint.json index 029010c0..05f4b41e 100644 --- a/pint.json +++ b/pint.json @@ -2,7 +2,7 @@ "preset": "laravel", "rules": { "php_unit_method_casing": { - "case": "camel_case" + "case": "camel_case" } } } diff --git a/tests/Feature/ConnectorTest.php b/tests/Feature/ConnectorTest.php index f4e330c3..91660ad2 100644 --- a/tests/Feature/ConnectorTest.php +++ b/tests/Feature/ConnectorTest.php @@ -12,7 +12,7 @@ class ConnectorTest extends \VladimirYuldashev\LaravelQueueRabbitMQ\Tests\TestCase { - public function test_lazy_connection(): void + public function testLazyConnection(): void { $this->app['config']->set('queue.connections.rabbitmq', [ 'driver' => 'rabbitmq', @@ -55,7 +55,7 @@ public function test_lazy_connection(): void $this->assertTrue($connection->getConnection()->isConnected()); } - public function test_lazy_stream_connection(): void + public function testLazyStreamConnection(): void { $this->app['config']->set('queue.connections.rabbitmq', [ 'driver' => 'rabbitmq', @@ -98,7 +98,7 @@ public function test_lazy_stream_connection(): void $this->assertTrue($connection->getConnection()->isConnected()); } - public function test_ssl_connection(): void + public function testSslConnection(): void { $this->markTestSkipped(); @@ -142,7 +142,7 @@ public function test_ssl_connection(): void } // Test to validate ssl connection params - public function test_no_verification_ssl_connection(): void + public function testNoVerificationSslConnection(): void { $this->app['config']->set('queue.connections.rabbitmq', [ 'driver' => 'rabbitmq', diff --git a/tests/Feature/QueueTest.php b/tests/Feature/QueueTest.php index 609a48d8..ee324c9a 100644 --- a/tests/Feature/QueueTest.php +++ b/tests/Feature/QueueTest.php @@ -20,12 +20,12 @@ protected function setUp(): void ]); } - public function test_connection(): void + public function testConnection(): void { $this->assertInstanceOf(AMQPStreamConnection::class, $this->connection()->getChannel()->getConnection()); } - public function test_without_reconnect(): void + public function testWithoutReconnect(): void { $queue = $this->connection('rabbitmq'); diff --git a/tests/Feature/SslQueueTest.php b/tests/Feature/SslQueueTest.php index 53cf5d38..02181c96 100644 --- a/tests/Feature/SslQueueTest.php +++ b/tests/Feature/SslQueueTest.php @@ -43,7 +43,7 @@ protected function getEnvironmentSetUp($app): void ]); } - public function test_connection(): void + public function testConnection(): void { $this->assertInstanceOf(AMQPSSLConnection::class, $this->connection()->getChannel()->getConnection()); } diff --git a/tests/Feature/TestCase.php b/tests/Feature/TestCase.php index 7d0fab9a..5afda85d 100644 --- a/tests/Feature/TestCase.php +++ b/tests/Feature/TestCase.php @@ -40,17 +40,17 @@ protected function tearDown(): void parent::tearDown(); } - public function test_size_does_not_throw_exception_on_unknown_queue(): void + public function testSizeDoesNotThrowExceptionOnUnknownQueue(): void { $this->assertEmpty(0, Queue::size(Str::random())); } - public function test_pop_nothing(): void + public function testPopNothing(): void { $this->assertNull(Queue::pop('foo')); } - public function test_push_raw(): void + public function testPushRaw(): void { Queue::pushRaw($payload = Str::random()); @@ -68,7 +68,7 @@ public function test_push_raw(): void $this->assertSame(0, Queue::size()); } - public function test_push(): void + public function testPush(): void { Queue::push(new TestJob); @@ -95,7 +95,7 @@ public function test_push(): void $this->assertSame(0, Queue::size()); } - public function test_push_after_commit(): void + public function testPushAfterCommit(): void { $transaction = new DatabaseTransactionsManager; @@ -122,7 +122,7 @@ public function test_push_after_commit(): void $this->assertSame(0, Queue::size()); } - public function test_later_raw(): void + public function testLaterRaw(): void { $payload = Str::random(); $data = [Str::random() => Str::random()]; @@ -152,7 +152,7 @@ public function test_later_raw(): void $this->assertSame(0, Queue::size()); } - public function test_later(): void + public function testLater(): void { Queue::later(3, new TestJob); @@ -179,7 +179,7 @@ public function test_later(): void $this->assertSame(0, Queue::size()); } - public function test_bulk(): void + public function testBulk(): void { $count = 100; $jobs = []; @@ -195,7 +195,7 @@ public function test_bulk(): void $this->assertSame($count, Queue::size()); } - public function test_push_encrypted(): void + public function testPushEncrypted(): void { Queue::push(new TestEncryptedJob); @@ -222,7 +222,7 @@ public function test_push_encrypted(): void $this->assertSame(0, Queue::size()); } - public function test_push_encrypted_after_commit(): void + public function testPushEncryptedAfterCommit(): void { $transaction = new DatabaseTransactionsManager; @@ -249,7 +249,7 @@ public function test_push_encrypted_after_commit(): void $this->assertSame(0, Queue::size()); } - public function test_encrypted_later(): void + public function testEncryptedLater(): void { Queue::later(3, new TestEncryptedJob); @@ -276,7 +276,7 @@ public function test_encrypted_later(): void $this->assertSame(0, Queue::size()); } - public function test_encrypted_bulk(): void + public function testEncryptedBulk(): void { $count = 100; $jobs = []; @@ -292,7 +292,7 @@ public function test_encrypted_bulk(): void $this->assertSame($count, Queue::size()); } - public function test_release_raw(): void + public function testReleaseRaw(): void { Queue::pushRaw($payload = Str::random()); @@ -318,7 +318,7 @@ public function test_release_raw(): void $this->assertSame(0, Queue::size()); } - public function test_release(): void + public function testRelease(): void { Queue::push(new TestJob); @@ -344,7 +344,7 @@ public function test_release(): void $this->assertSame(0, Queue::size()); } - public function test_release_with_delay_raw(): void + public function testReleaseWithDelayRaw(): void { Queue::pushRaw($payload = Str::random()); @@ -375,7 +375,7 @@ public function test_release_with_delay_raw(): void $this->assertSame(0, Queue::size()); } - public function test_release_in_the_past(): void + public function testReleaseInThePast(): void { Queue::push(new TestJob); @@ -390,7 +390,7 @@ public function test_release_in_the_past(): void $this->assertSame(0, Queue::size()); } - public function test_release_and_release_with_delay_attempts(): void + public function testReleaseAndReleaseWithDelayAttempts(): void { Queue::push(new TestJob); @@ -417,7 +417,7 @@ public function test_release_and_release_with_delay_attempts(): void $this->assertSame(0, Queue::size()); } - public function test_delete(): void + public function testDelete(): void { Queue::push(new TestJob); @@ -431,7 +431,7 @@ public function test_delete(): void $this->assertNull(Queue::pop()); } - public function test_failed(): void + public function testFailed(): void { Queue::push(new TestJob); diff --git a/tests/Functional/RabbitMQQueueTest.php b/tests/Functional/RabbitMQQueueTest.php index 21a2e1d4..1c5d94fb 100644 --- a/tests/Functional/RabbitMQQueueTest.php +++ b/tests/Functional/RabbitMQQueueTest.php @@ -9,7 +9,7 @@ class RabbitMQQueueTest extends BaseTestCase { - public function test_connection(): void + public function testConnection(): void { $queue = $this->connection(); $this->assertInstanceOf(RabbitMQQueue::class, $queue); @@ -21,7 +21,7 @@ public function test_connection(): void $this->assertInstanceOf(RabbitMQQueue::class, $queue); } - public function test_config_reroute_failed(): void + public function testConfigRerouteFailed(): void { $queue = $this->connection(); $this->assertFalse($this->callProperty($queue, 'config')->isRerouteFailed()); @@ -36,7 +36,7 @@ public function test_config_reroute_failed(): void $this->assertFalse($this->callProperty($queue, 'config')->isRerouteFailed()); } - public function test_config_prioritize_delayed(): void + public function testConfigPrioritizeDelayed(): void { $queue = $this->connection(); $this->assertFalse($this->callProperty($queue, 'config')->isPrioritizeDelayed()); @@ -51,7 +51,7 @@ public function test_config_prioritize_delayed(): void $this->assertFalse($this->callProperty($queue, 'config')->isPrioritizeDelayed()); } - public function test_queue_max_priority(): void + public function testQueueMaxPriority(): void { $queue = $this->connection(); $this->assertIsInt($this->callProperty($queue, 'config')->getQueueMaxPriority()); @@ -70,7 +70,7 @@ public function test_queue_max_priority(): void $this->assertSame(2, $this->callProperty($queue, 'config')->getQueueMaxPriority()); } - public function test_config_exchange_type(): void + public function testConfigExchangeType(): void { $queue = $this->connection(); $this->assertSame(AMQPExchangeType::DIRECT, $this->callMethod($queue, 'getExchangeType')); @@ -92,7 +92,7 @@ public function test_config_exchange_type(): void $this->assertSame(AMQPExchangeType::DIRECT, $this->callMethod($queue, 'getExchangeType')); } - public function test_exchange(): void + public function testExchange(): void { $queue = $this->connection(); $this->assertSame('test', $this->callMethod($queue, 'getExchange', ['test'])); @@ -119,7 +119,7 @@ public function test_exchange(): void $this->assertSame('', $this->callMethod($queue, 'getExchange', [''])); } - public function test_failed_exchange(): void + public function testFailedExchange(): void { $queue = $this->connection(); $this->assertSame('test', $this->callMethod($queue, 'getFailedExchange', ['test'])); @@ -146,7 +146,7 @@ public function test_failed_exchange(): void $this->assertSame('', $this->callMethod($queue, 'getFailedExchange', [''])); } - public function test_routing_key(): void + public function testRoutingKey(): void { $queue = $this->connection(); $this->assertSame('test', $this->callMethod($queue, 'getRoutingKey', ['test'])); @@ -165,7 +165,7 @@ public function test_routing_key(): void $this->assertSame('an.alternate.routing-key', $this->callMethod($queue, 'getRoutingKey', ['test'])); } - public function test_failed_routing_key(): void + public function testFailedRoutingKey(): void { $queue = $this->connection(); $this->assertSame('test.failed', $this->callMethod($queue, 'getFailedRoutingKey', ['test'])); @@ -184,7 +184,7 @@ public function test_failed_routing_key(): void $this->assertSame('an.alternate.routing-key', $this->callMethod($queue, 'getFailedRoutingKey', ['test'])); } - public function test_config_quorum(): void + public function testConfigQuorum(): void { $queue = $this->connection(); $this->assertFalse($this->callProperty($queue, 'config')->isQuorum()); @@ -202,7 +202,7 @@ public function test_config_quorum(): void $this->assertTrue($this->callProperty($queue, 'config')->isQuorum()); } - public function test_declare_delete_exchange(): void + public function testDeclareDeleteExchange(): void { $queue = $this->connection(); @@ -217,7 +217,7 @@ public function test_declare_delete_exchange(): void $this->assertFalse($queue->isExchangeExists($name)); } - public function test_declare_delete_queue(): void + public function testDeclareDeleteQueue(): void { $queue = $this->connection(); @@ -232,7 +232,7 @@ public function test_declare_delete_queue(): void $this->assertFalse($queue->isQueueExists($name)); } - public function test_queue_arguments(): void + public function testQueueArguments(): void { $name = Str::random(); @@ -272,7 +272,7 @@ public function test_queue_arguments(): void $this->assertEquals(array_values($expected), array_values($actual)); } - public function test_delay_queue_arguments(): void + public function testDelayQueueArguments(): void { $name = Str::random(); $ttl = 12000; diff --git a/tests/Functional/TestCase.php b/tests/Functional/TestCase.php index b21aeaf8..8b843561 100644 --- a/tests/Functional/TestCase.php +++ b/tests/Functional/TestCase.php @@ -236,7 +236,7 @@ protected function callProperty($object, string $property): mixed return $property->getValue($object); } - public function test_connect_channel(): void + public function testConnectChannel(): void { $queue = $this->connection(); $this->assertFalse($queue->getConnection()->isConnected()); @@ -248,7 +248,7 @@ public function test_connect_channel(): void $this->assertTrue($channel->is_open()); } - public function test_reconnect(): void + public function testReconnect(): void { $queue = $this->connection(); $this->assertFalse($queue->getConnection()->isConnected()); From b6c9fa88170b02725d7606192dc676e7bb36e32a Mon Sep 17 00:00:00 2001 From: Frederik Sauer Date: Tue, 21 Oct 2025 09:07:19 +0200 Subject: [PATCH 09/10] Fix compatibility with Laravel 12.34 --- src/Queue/RabbitMQQueue.php | 32 ++++++++--------- tests/Functional/RabbitMQQueueTest.php | 48 +++++++++++++------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/Queue/RabbitMQQueue.php b/src/Queue/RabbitMQQueue.php index fadedce5..04377a0d 100644 --- a/src/Queue/RabbitMQQueue.php +++ b/src/Queue/RabbitMQQueue.php @@ -62,14 +62,14 @@ class RabbitMQQueue extends Queue implements QueueContract, RabbitMQQueueContrac /** * Holds the Configuration */ - protected QueueConfig $config; + protected QueueConfig $rabbitMQConfig; /** * RabbitMQQueue constructor. */ public function __construct(QueueConfig $config) { - $this->config = $config; + $this->rabbitMQConfig = $config; $this->dispatchAfterCommit = $config->isDispatchAfterCommit(); } @@ -293,7 +293,7 @@ public function setConnection(AbstractConnection $connection): RabbitMQQueue */ public function getJobClass(): string { - $job = $this->getConfig()->getAbstractJob(); + $job = $this->getRabbitMQConfig()->getAbstractJob(); throw_if( ! is_a($job, RabbitMQJob::class, true), @@ -309,7 +309,7 @@ public function getJobClass(): string */ public function getQueue($queue = null): string { - return $queue ?: $this->getConfig()->getQueue(); + return $queue ?: $this->getRabbitMQConfig()->getQueue(); } /** @@ -523,7 +523,7 @@ protected function createMessage($payload, int $attempts = 0): array $properties['correlation_id'] = $correlationId; } - if ($this->getConfig()->isPrioritizeDelayed()) { + if ($this->getRabbitMQConfig()->isPrioritizeDelayed()) { $properties['priority'] = $attempts; } @@ -605,16 +605,16 @@ protected function getQueueArguments(string $destination): array // Messages with a priority which is higher than the queue's maximum, are treated as if they were // published with the maximum priority. // Quorum queues does not support priority. - if ($this->getConfig()->isPrioritizeDelayed() && ! $this->getConfig()->isQuorum()) { - $arguments['x-max-priority'] = $this->getConfig()->getQueueMaxPriority(); + if ($this->getRabbitMQConfig()->isPrioritizeDelayed() && ! $this->getRabbitMQConfig()->isQuorum()) { + $arguments['x-max-priority'] = $this->getRabbitMQConfig()->getQueueMaxPriority(); } - if ($this->getConfig()->isRerouteFailed()) { + if ($this->getRabbitMQConfig()->isRerouteFailed()) { $arguments['x-dead-letter-exchange'] = $this->getFailedExchange(); $arguments['x-dead-letter-routing-key'] = $this->getFailedRoutingKey($destination); } - if ($this->getConfig()->isQuorum()) { + if ($this->getRabbitMQConfig()->isQuorum()) { $arguments['x-queue-type'] = 'quorum'; } @@ -639,7 +639,7 @@ protected function getDelayQueueArguments(string $destination, int $ttl): array */ protected function getExchange(?string $exchange = null): string { - return $exchange ?? $this->getConfig()->getExchange(); + return $exchange ?? $this->getRabbitMQConfig()->getExchange(); } /** @@ -648,7 +648,7 @@ protected function getExchange(?string $exchange = null): string */ protected function getRoutingKey(string $destination): string { - return ltrim(sprintf($this->getConfig()->getExchangeRoutingKey(), $destination), '.'); + return ltrim(sprintf($this->getRabbitMQConfig()->getExchangeRoutingKey(), $destination), '.'); } /** @@ -656,7 +656,7 @@ protected function getRoutingKey(string $destination): string */ protected function getExchangeType(?string $type = null): string { - $constant = AMQPExchangeType::class.'::'.Str::upper($type ?: $this->getConfig()->getExchangeType()); + $constant = AMQPExchangeType::class.'::'.Str::upper($type ?: $this->getRabbitMQConfig()->getExchangeType()); return defined($constant) ? constant($constant) : AMQPExchangeType::DIRECT; } @@ -666,7 +666,7 @@ protected function getExchangeType(?string $type = null): string */ protected function getFailedExchange(?string $exchange = null): string { - return $exchange ?? $this->getConfig()->getFailedExchange(); + return $exchange ?? $this->getRabbitMQConfig()->getFailedExchange(); } /** @@ -675,7 +675,7 @@ protected function getFailedExchange(?string $exchange = null): string */ protected function getFailedRoutingKey(string $destination): string { - return ltrim(sprintf($this->getConfig()->getFailedRoutingKey(), $destination), '.'); + return ltrim(sprintf($this->getRabbitMQConfig()->getFailedRoutingKey(), $destination), '.'); } /** @@ -735,9 +735,9 @@ protected function publishProperties($queue, array $options = []): array return [$destination, $exchange, $exchangeType, $attempts]; } - protected function getConfig(): QueueConfig + protected function getRabbitMQConfig(): QueueConfig { - return $this->config; + return $this->rabbitMQConfig; } /** diff --git a/tests/Functional/RabbitMQQueueTest.php b/tests/Functional/RabbitMQQueueTest.php index 21a2e1d4..e190f3f0 100644 --- a/tests/Functional/RabbitMQQueueTest.php +++ b/tests/Functional/RabbitMQQueueTest.php @@ -24,50 +24,50 @@ public function test_connection(): void public function test_config_reroute_failed(): void { $queue = $this->connection(); - $this->assertFalse($this->callProperty($queue, 'config')->isRerouteFailed()); + $this->assertFalse($this->callProperty($queue, 'rabbitMQConfig')->isRerouteFailed()); $queue = $this->connection('rabbitmq-with-options'); - $this->assertTrue($this->callProperty($queue, 'config')->isRerouteFailed()); + $this->assertTrue($this->callProperty($queue, 'rabbitMQConfig')->isRerouteFailed()); $queue = $this->connection('rabbitmq-with-options-empty'); - $this->assertFalse($this->callProperty($queue, 'config')->isRerouteFailed()); + $this->assertFalse($this->callProperty($queue, 'rabbitMQConfig')->isRerouteFailed()); $queue = $this->connection('rabbitmq-with-options-null'); - $this->assertFalse($this->callProperty($queue, 'config')->isRerouteFailed()); + $this->assertFalse($this->callProperty($queue, 'rabbitMQConfig')->isRerouteFailed()); } public function test_config_prioritize_delayed(): void { $queue = $this->connection(); - $this->assertFalse($this->callProperty($queue, 'config')->isPrioritizeDelayed()); + $this->assertFalse($this->callProperty($queue, 'rabbitMQConfig')->isPrioritizeDelayed()); $queue = $this->connection('rabbitmq-with-options'); - $this->assertTrue($this->callProperty($queue, 'config')->isPrioritizeDelayed()); + $this->assertTrue($this->callProperty($queue, 'rabbitMQConfig')->isPrioritizeDelayed()); $queue = $this->connection('rabbitmq-with-options-empty'); - $this->assertFalse($this->callProperty($queue, 'config')->isPrioritizeDelayed()); + $this->assertFalse($this->callProperty($queue, 'rabbitMQConfig')->isPrioritizeDelayed()); $queue = $this->connection('rabbitmq-with-options-null'); - $this->assertFalse($this->callProperty($queue, 'config')->isPrioritizeDelayed()); + $this->assertFalse($this->callProperty($queue, 'rabbitMQConfig')->isPrioritizeDelayed()); } public function test_queue_max_priority(): void { $queue = $this->connection(); - $this->assertIsInt($this->callProperty($queue, 'config')->getQueueMaxPriority()); - $this->assertSame(2, $this->callProperty($queue, 'config')->getQueueMaxPriority()); + $this->assertIsInt($this->callProperty($queue, 'rabbitMQConfig')->getQueueMaxPriority()); + $this->assertSame(2, $this->callProperty($queue, 'rabbitMQConfig')->getQueueMaxPriority()); $queue = $this->connection('rabbitmq-with-options'); - $this->assertIsInt($this->callProperty($queue, 'config')->getQueueMaxPriority()); - $this->assertSame(20, $this->callProperty($queue, 'config')->getQueueMaxPriority()); + $this->assertIsInt($this->callProperty($queue, 'rabbitMQConfig')->getQueueMaxPriority()); + $this->assertSame(20, $this->callProperty($queue, 'rabbitMQConfig')->getQueueMaxPriority()); $queue = $this->connection('rabbitmq-with-options-empty'); - $this->assertIsInt($this->callProperty($queue, 'config')->getQueueMaxPriority()); - $this->assertSame(2, $this->callProperty($queue, 'config')->getQueueMaxPriority()); + $this->assertIsInt($this->callProperty($queue, 'rabbitMQConfig')->getQueueMaxPriority()); + $this->assertSame(2, $this->callProperty($queue, 'rabbitMQConfig')->getQueueMaxPriority()); $queue = $this->connection('rabbitmq-with-options-null'); - $this->assertIsInt($this->callProperty($queue, 'config')->getQueueMaxPriority()); - $this->assertSame(2, $this->callProperty($queue, 'config')->getQueueMaxPriority()); + $this->assertIsInt($this->callProperty($queue, 'rabbitMQConfig')->getQueueMaxPriority()); + $this->assertSame(2, $this->callProperty($queue, 'rabbitMQConfig')->getQueueMaxPriority()); } public function test_config_exchange_type(): void @@ -88,7 +88,7 @@ public function test_config_exchange_type(): void $this->assertSame(AMQPExchangeType::DIRECT, $this->callMethod($queue, 'getExchangeType')); // testing an unkown type with a default - $this->callProperty($queue, 'config')->setExchangeType('unknown'); + $this->callProperty($queue, 'rabbitMQConfig')->setExchangeType('unknown'); $this->assertSame(AMQPExchangeType::DIRECT, $this->callMethod($queue, 'getExchangeType')); } @@ -161,7 +161,7 @@ public function test_routing_key(): void $queue = $this->connection('rabbitmq-with-options-null'); $this->assertSame('test', $this->callMethod($queue, 'getRoutingKey', ['test'])); - $this->callProperty($queue, 'config')->setExchangeRoutingKey('.an.alternate.routing-key'); + $this->callProperty($queue, 'rabbitMQConfig')->setExchangeRoutingKey('.an.alternate.routing-key'); $this->assertSame('an.alternate.routing-key', $this->callMethod($queue, 'getRoutingKey', ['test'])); } @@ -180,26 +180,26 @@ public function test_failed_routing_key(): void $queue = $this->connection('rabbitmq-with-options-null'); $this->assertSame('test.failed', $this->callMethod($queue, 'getFailedRoutingKey', ['test'])); - $this->callProperty($queue, 'config')->setFailedRoutingKey('.an.alternate.routing-key'); + $this->callProperty($queue, 'rabbitMQConfig')->setFailedRoutingKey('.an.alternate.routing-key'); $this->assertSame('an.alternate.routing-key', $this->callMethod($queue, 'getFailedRoutingKey', ['test'])); } public function test_config_quorum(): void { $queue = $this->connection(); - $this->assertFalse($this->callProperty($queue, 'config')->isQuorum()); + $this->assertFalse($this->callProperty($queue, 'rabbitMQConfig')->isQuorum()); $queue = $this->connection('rabbitmq-with-options'); - $this->assertFalse($this->callProperty($queue, 'config')->isQuorum()); + $this->assertFalse($this->callProperty($queue, 'rabbitMQConfig')->isQuorum()); $queue = $this->connection('rabbitmq-with-options-empty'); - $this->assertFalse($this->callProperty($queue, 'config')->isQuorum()); + $this->assertFalse($this->callProperty($queue, 'rabbitMQConfig')->isQuorum()); $queue = $this->connection('rabbitmq-with-options-null'); - $this->assertFalse($this->callProperty($queue, 'config')->isQuorum()); + $this->assertFalse($this->callProperty($queue, 'rabbitMQConfig')->isQuorum()); $queue = $this->connection('rabbitmq-with-quorum-options'); - $this->assertTrue($this->callProperty($queue, 'config')->isQuorum()); + $this->assertTrue($this->callProperty($queue, 'rabbitMQConfig')->isQuorum()); } public function test_declare_delete_exchange(): void From faa8307cb45ff8079627c2a9b0c20f0f20319e94 Mon Sep 17 00:00:00 2001 From: Frederik Sauer Date: Tue, 11 Nov 2025 15:16:02 +0100 Subject: [PATCH 10/10] Properly handle skipped tests --- .gitignore | 2 +- tests/Feature/SslQueueTest.php | 4 ++++ tests/Feature/TestCase.php | 21 +++++++++++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 00dea824..a2dcf885 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,5 @@ composer.lock .phpstorm.meta.php phpunit.xml -.phpunit.result.cache +.phpunit.* .php_cs.cache diff --git a/tests/Feature/SslQueueTest.php b/tests/Feature/SslQueueTest.php index 02181c96..11c93f5a 100644 --- a/tests/Feature/SslQueueTest.php +++ b/tests/Feature/SslQueueTest.php @@ -6,8 +6,12 @@ class SslQueueTest extends TestCase { + protected bool $interactsWithConnection = false; + protected function setUp(): void { + parent::setUp(); + $this->markTestSkipped(); } diff --git a/tests/Feature/TestCase.php b/tests/Feature/TestCase.php index 5afda85d..f8a9cb05 100644 --- a/tests/Feature/TestCase.php +++ b/tests/Feature/TestCase.php @@ -14,6 +14,11 @@ abstract class TestCase extends BaseTestCase { + /** + * Set to false for skipped tests. + */ + protected bool $interactsWithConnection = true; + /** * @throws AMQPProtocolChannelException */ @@ -21,8 +26,10 @@ protected function setUp(): void { parent::setUp(); - if ($this->connection()->isQueueExists()) { - $this->connection()->purge(); + if ($this->interactsWithConnection) { + if ($this->connection()->isQueueExists()) { + $this->connection()->purge(); + } } } @@ -31,11 +38,13 @@ protected function setUp(): void */ protected function tearDown(): void { - if ($this->connection()->isQueueExists()) { - $this->connection()->purge(); - } + if ($this->interactsWithConnection) { + if ($this->connection()->isQueueExists()) { + $this->connection()->purge(); + } - self::assertSame(0, Queue::size()); + self::assertSame(0, Queue::size()); + } parent::tearDown(); }