diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 1185b9c..2446c56 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,5 +1,7 @@ exclude('build') ->append([__FILE__]); -$overrides = []; +$overrides = [ + 'declare_strict_types' => true, + 'void_return' => true, +]; $options = [ 'finder' => $finder, diff --git a/src/BaseJob.php b/src/BaseJob.php index ad67410..2a632ea 100644 --- a/src/BaseJob.php +++ b/src/BaseJob.php @@ -1,5 +1,7 @@ getNamespace('CodeIgniter\\Queue')[0]; diff --git a/src/Commands/QueueRetry.php b/src/Commands/QueueRetry.php index ad993b5..88eed8d 100644 --- a/src/Commands/QueueRetry.php +++ b/src/Commands/QueueRetry.php @@ -1,5 +1,7 @@ forge->addField([ 'id' => ['type' => 'bigint', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], @@ -34,7 +36,7 @@ public function up() $this->forge->createTable('queue_jobs_failed', true); } - public function down() + public function down(): void { $this->forge->dropTable('queue_jobs', true); $this->forge->dropTable('queue_jobs_failed', true); diff --git a/src/Database/Migrations/2023-11-05-064053_AddPriorityField.php b/src/Database/Migrations/2023-11-05-064053_AddPriorityField.php index f437963..a4cf410 100644 --- a/src/Database/Migrations/2023-11-05-064053_AddPriorityField.php +++ b/src/Database/Migrations/2023-11-05-064053_AddPriorityField.php @@ -1,5 +1,7 @@ [ @@ -40,7 +42,7 @@ public function up() $this->forge->processIndexes('queue_jobs'); } - public function down() + public function down(): void { // Ugly fix for dropping the correct index $keys = $this->db->getIndexData('queue_jobs'); diff --git a/src/Entities/QueueJob.php b/src/Entities/QueueJob.php index 28fac48..b4c6523 100644 --- a/src/Entities/QueueJob.php +++ b/src/Entities/QueueJob.php @@ -1,5 +1,7 @@ [ 'className' => [ diff --git a/src/Models/QueueJobFailedModel.php b/src/Models/QueueJobFailedModel.php index 2087946..92270f6 100644 --- a/src/Models/QueueJobFailedModel.php +++ b/src/Models/QueueJobFailedModel.php @@ -1,5 +1,7 @@ config = config(QueueConfig::class); } - public function testDatabaseHandler() + public function testDatabaseHandler(): void { $handler = new DatabaseHandler($this->config); $this->assertInstanceOf(DatabaseHandler::class, $handler); } - public function testPriority() + public function testPriority(): void { $handler = new DatabaseHandler($this->config); $handler->setPriority('high'); @@ -45,7 +47,7 @@ public function testPriority() $this->assertSame('high', self::getPrivateProperty($handler, 'priority')); } - public function testPriorityNameException() + public function testPriorityNameException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('The priority name should consists only lowercase letters.'); @@ -54,7 +56,7 @@ public function testPriorityNameException() $handler->setPriority('high_:'); } - public function testPriorityNameLengthException() + public function testPriorityNameLengthException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('The priority name is too long. It should be no longer than 64 letters.'); @@ -66,7 +68,7 @@ public function testPriorityNameLengthException() /** * @throws ReflectionException */ - public function testPush() + public function testPush(): void { $handler = new DatabaseHandler($this->config); $result = $handler->push('queue', 'success', ['key' => 'value']); @@ -81,7 +83,7 @@ public function testPush() /** * @throws ReflectionException */ - public function testPushWithPriority() + public function testPushWithPriority(): void { $handler = new DatabaseHandler($this->config); $result = $handler->setPriority('high')->push('queue', 'success', ['key' => 'value']); @@ -94,7 +96,7 @@ public function testPushWithPriority() ]); } - public function testPushAndPopWithPriority() + public function testPushAndPopWithPriority(): void { $handler = new DatabaseHandler($this->config); $result = $handler->push('queue', 'success', ['key1' => 'value1']); @@ -129,7 +131,7 @@ public function testPushAndPopWithPriority() /** * @throws ReflectionException */ - public function testPushException() + public function testPushException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('This job name is not defined in the $jobHandlers array.'); @@ -141,7 +143,7 @@ public function testPushException() /** * @throws ReflectionException */ - public function testPushWithPriorityException() + public function testPushWithPriorityException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('This queue has incorrectly defined priority: "invalid" for the queue: "queue".'); @@ -153,7 +155,7 @@ public function testPushWithPriorityException() /** * @throws ReflectionException */ - public function testPushWithIncorrectQueueFormatException() + public function testPushWithIncorrectQueueFormatException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('The queue name should consists only lowercase letters or numbers.'); @@ -165,7 +167,7 @@ public function testPushWithIncorrectQueueFormatException() /** * @throws ReflectionException */ - public function testPushWithTooLongQueueNameException() + public function testPushWithTooLongQueueNameException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('The queue name is too long. It should be no longer than 64 letters.'); @@ -177,7 +179,7 @@ public function testPushWithTooLongQueueNameException() /** * @throws ReflectionException */ - public function testPop() + public function testPop(): void { $handler = new DatabaseHandler($this->config); $result = $handler->pop('queue1', ['default']); @@ -192,7 +194,7 @@ public function testPop() /** * @throws ReflectionException */ - public function testPopEmpty() + public function testPopEmpty(): void { $handler = new DatabaseHandler($this->config); $result = $handler->pop('queue123', ['default']); @@ -203,7 +205,7 @@ public function testPopEmpty() /** * @throws ReflectionException */ - public function testLater() + public function testLater(): void { $handler = new DatabaseHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -225,7 +227,7 @@ public function testLater() /** * @throws ReflectionException */ - public function testFailedAndKeepJob() + public function testFailedAndKeepJob(): void { $handler = new DatabaseHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -244,7 +246,7 @@ public function testFailedAndKeepJob() ]); } - public function testFailedAndDontKeepJob() + public function testFailedAndDontKeepJob(): void { $handler = new DatabaseHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -266,7 +268,7 @@ public function testFailedAndDontKeepJob() /** * @throws ReflectionException */ - public function testDoneAndKeepJob() + public function testDoneAndKeepJob(): void { $handler = new DatabaseHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -283,7 +285,7 @@ public function testDoneAndKeepJob() /** * @throws ReflectionException */ - public function testDoneAndDontKeepJob() + public function testDoneAndDontKeepJob(): void { $handler = new DatabaseHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -296,7 +298,7 @@ public function testDoneAndDontKeepJob() ]); } - public function testClear() + public function testClear(): void { $handler = new DatabaseHandler($this->config); $result = $handler->clear('queue1'); @@ -311,7 +313,7 @@ public function testClear() ]); } - public function testRetry() + public function testRetry(): void { $handler = new DatabaseHandler($this->config); $count = $handler->retry(1, 'queue1'); @@ -328,7 +330,7 @@ public function testRetry() ]); } - public function testForget() + public function testForget(): void { $handler = new DatabaseHandler($this->config); $result = $handler->forget(1); @@ -340,7 +342,7 @@ public function testForget() ]); } - public function testForgetFalse() + public function testForgetFalse(): void { $handler = new DatabaseHandler($this->config); $result = $handler->forget(1111); @@ -351,7 +353,7 @@ public function testForgetFalse() /** * @throws ReflectionException */ - public function testFlush() + public function testFlush(): void { $handler = new DatabaseHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -373,7 +375,7 @@ public function testFlush() ]); } - public function testFlushAll() + public function testFlushAll(): void { $handler = new DatabaseHandler($this->config); $handler->flush(null, null); @@ -382,7 +384,7 @@ public function testFlushAll() ]); } - public function testListFailed() + public function testListFailed(): void { $handler = new DatabaseHandler($this->config); $list = $handler->listFailed('queue1'); diff --git a/tests/PredisHandlerTest.php b/tests/PredisHandlerTest.php index 6cccdfe..ba7a40c 100644 --- a/tests/PredisHandlerTest.php +++ b/tests/PredisHandlerTest.php @@ -1,5 +1,7 @@ config = config(QueueConfig::class); } - public function testPredisHandler() + public function testPredisHandler(): void { $handler = new PredisHandler($this->config); $this->assertInstanceOf(PredisHandler::class, $handler); } - public function testPriority() + public function testPriority(): void { $handler = new PredisHandler($this->config); $handler->setPriority('high'); @@ -44,7 +46,7 @@ public function testPriority() $this->assertSame('high', self::getPrivateProperty($handler, 'priority')); } - public function testPriorityException() + public function testPriorityException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('The priority name should consists only lowercase letters.'); @@ -56,7 +58,7 @@ public function testPriorityException() /** * @throws ReflectionException */ - public function testPush() + public function testPush(): void { $handler = new PredisHandler($this->config); $result = $handler->push('queue', 'success', ['key' => 'value']); @@ -75,7 +77,7 @@ public function testPush() /** * @throws ReflectionException */ - public function testPushWithPriority() + public function testPushWithPriority(): void { $handler = new PredisHandler($this->config); $result = $handler->setPriority('high')->push('queue', 'success', ['key' => 'value']); @@ -91,7 +93,7 @@ public function testPushWithPriority() $this->assertSame(['key' => 'value'], $queueJob->payload['data']); } - public function testPushException() + public function testPushException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('This job name is not defined in the $jobHandlers array.'); @@ -100,7 +102,7 @@ public function testPushException() $handler->push('queue', 'not-exists', ['key' => 'value']); } - public function testPushWithPriorityException() + public function testPushWithPriorityException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('This queue has incorrectly defined priority: "invalid" for the queue: "queue".'); @@ -112,7 +114,7 @@ public function testPushWithPriorityException() /** * @throws ReflectionException */ - public function testPop() + public function testPop(): void { $handler = new PredisHandler($this->config); $result = $handler->pop('queue1', ['default']); @@ -125,7 +127,7 @@ public function testPop() $this->assertSame(1, $predis->hexists('queues:queue1::reserved', $result->id)); } - public function testPopEmpty() + public function testPopEmpty(): void { $handler = new PredisHandler($this->config); $result = $handler->pop('queue123', ['default']); @@ -136,7 +138,7 @@ public function testPopEmpty() /** * @throws ReflectionException */ - public function testLater() + public function testLater(): void { $handler = new PredisHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -155,7 +157,7 @@ public function testLater() /** * @throws ReflectionException */ - public function testFailedAndKeepJob() + public function testFailedAndKeepJob(): void { $handler = new PredisHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -179,7 +181,7 @@ public function testFailedAndKeepJob() /** * @throws ReflectionException */ - public function testFailedAndDontKeepJob() + public function testFailedAndDontKeepJob(): void { $handler = new PredisHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -203,7 +205,7 @@ public function testFailedAndDontKeepJob() /** * @throws ReflectionException */ - public function testDoneAndKeepJob() + public function testDoneAndKeepJob(): void { $handler = new PredisHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -220,7 +222,7 @@ public function testDoneAndKeepJob() /** * @throws ReflectionException */ - public function testDoneAndDontKeepJob() + public function testDoneAndDontKeepJob(): void { $handler = new PredisHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -238,7 +240,7 @@ public function testDoneAndDontKeepJob() /** * @throws ReflectionException */ - public function testClear() + public function testClear(): void { $handler = new PredisHandler($this->config); $result = $handler->clear('queue1'); @@ -255,7 +257,7 @@ public function testClear() /** * @throws ReflectionException */ - public function testClearAll() + public function testClearAll(): void { $handler = new PredisHandler($this->config); $result = $handler->clear(); @@ -272,7 +274,7 @@ public function testClearAll() /** * @throws ReflectionException */ - public function testRetry() + public function testRetry(): void { $handler = new PredisHandler($this->config); $count = $handler->retry(1, 'queue1'); diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 0bd655b..377dc43 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -1,5 +1,7 @@ config = config(QueueConfig::class); } - public function testQueue() + public function testQueue(): void { $queue = new Queue($this->config); $this->assertInstanceOf(Queue::class, $queue); } - public function testQueueException() + public function testQueueException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('This queue handler is incorrect.'); @@ -41,7 +43,7 @@ public function testQueueException() $this->assertInstanceOf(Queue::class, $queue); } - public function testQueueInit() + public function testQueueInit(): void { $queue = new Queue($this->config); $this->assertInstanceOf(DatabaseHandler::class, $queue->init()); diff --git a/tests/RedisHandlerTest.php b/tests/RedisHandlerTest.php index ddc9f6a..8605b99 100644 --- a/tests/RedisHandlerTest.php +++ b/tests/RedisHandlerTest.php @@ -31,13 +31,13 @@ protected function setUp(): void $this->config = config(QueueConfig::class); } - public function testRedisHandler() + public function testRedisHandler(): void { $handler = new RedisHandler($this->config); $this->assertInstanceOf(RedisHandler::class, $handler); } - public function testPriority() + public function testPriority(): void { $handler = new RedisHandler($this->config); $handler->setPriority('high'); @@ -45,7 +45,7 @@ public function testPriority() $this->assertSame('high', self::getPrivateProperty($handler, 'priority')); } - public function testPriorityException() + public function testPriorityException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('The priority name should consists only lowercase letters.'); @@ -54,7 +54,7 @@ public function testPriorityException() $handler->setPriority('high_:'); } - public function testPush() + public function testPush(): void { $handler = new RedisHandler($this->config); $result = $handler->push('queue', 'success', ['key' => 'value']); @@ -70,7 +70,7 @@ public function testPush() $this->assertSame(['key' => 'value'], $queueJob->payload['data']); } - public function testPushWithPriority() + public function testPushWithPriority(): void { $handler = new RedisHandler($this->config); $result = $handler->setPriority('high')->push('queue', 'success', ['key' => 'value']); @@ -86,7 +86,7 @@ public function testPushWithPriority() $this->assertSame(['key' => 'value'], $queueJob->payload['data']); } - public function testPushException() + public function testPushException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('This job name is not defined in the $jobHandlers array.'); @@ -95,7 +95,7 @@ public function testPushException() $handler->push('queue', 'not-exists', ['key' => 'value']); } - public function testPushWithPriorityException() + public function testPushWithPriorityException(): void { $this->expectException(QueueException::class); $this->expectExceptionMessage('This queue has incorrectly defined priority: "invalid" for the queue: "queue".'); @@ -104,7 +104,7 @@ public function testPushWithPriorityException() $handler->setPriority('invalid')->push('queue', 'success', ['key' => 'value']); } - public function testPop() + public function testPop(): void { $handler = new RedisHandler($this->config); $result = $handler->pop('queue1', ['default']); @@ -117,7 +117,7 @@ public function testPop() $this->assertTrue($redis->hExists('queues:queue1::reserved', (string) $result->id)); } - public function testPopEmpty() + public function testPopEmpty(): void { $handler = new RedisHandler($this->config); $result = $handler->pop('queue123', ['default']); @@ -125,7 +125,7 @@ public function testPopEmpty() $this->assertNull($result); } - public function testLater() + public function testLater(): void { $handler = new RedisHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -141,7 +141,7 @@ public function testLater() $this->assertSame(1, $redis->zCard('queues:queue1:default')); } - public function testFailedAndKeepJob() + public function testFailedAndKeepJob(): void { $handler = new RedisHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -162,7 +162,7 @@ public function testFailedAndKeepJob() ]); } - public function testFailedAndDontKeepJob() + public function testFailedAndDontKeepJob(): void { $handler = new RedisHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -183,7 +183,7 @@ public function testFailedAndDontKeepJob() ]); } - public function testDoneAndKeepJob() + public function testDoneAndKeepJob(): void { $handler = new RedisHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -197,7 +197,7 @@ public function testDoneAndKeepJob() $this->assertSame(1, $redis->lLen('queues:queue1::done')); } - public function testDoneAndDontKeepJob() + public function testDoneAndDontKeepJob(): void { $handler = new RedisHandler($this->config); $queueJob = $handler->pop('queue1', ['default']); @@ -212,7 +212,7 @@ public function testDoneAndDontKeepJob() $this->assertSame(0, $redis->lLen('queues:queue1::done')); } - public function testClear() + public function testClear(): void { $handler = new RedisHandler($this->config); $result = $handler->clear('queue1'); @@ -226,7 +226,7 @@ public function testClear() $this->assertTrue($result); } - public function testClearAll() + public function testClearAll(): void { $handler = new RedisHandler($this->config); @@ -240,7 +240,7 @@ public function testClearAll() $this->assertTrue($result); } - public function testRetry() + public function testRetry(): void { $handler = new RedisHandler($this->config); $count = $handler->retry(1, 'queue1'); diff --git a/tests/_support/Config/Queue.php b/tests/_support/Config/Queue.php index d71bee9..24097e2 100644 --- a/tests/_support/Config/Queue.php +++ b/tests/_support/Config/Queue.php @@ -1,5 +1,7 @@