Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="2.1.17" installed="2.1.17" location="./tools/phpstan" copy="false"/>
<phar name="phpstan" version="2.1.31" installed="2.1.31" location="./tools/phpstan" copy="false"/>
</phive>
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
},
"require": {
"php": ">=8.1",
"cakephp/cakephp": "^5.0.0",
"cakephp/cakephp": "^5.1.0",
"enqueue/simple-client": "^0.10",
"psr/log": "^3.0"
},
"require-dev": {
"cakephp/bake": "^3.0.0",
"cakephp/bake": "^3.5.1",
"cakephp/cakephp-codesniffer": "^5.0",
"enqueue/fs": "^0.10",
"phpunit/phpunit": "^10.1.0"
"phpunit/phpunit": "^10.5.32 || ^11.3.3 || ^12.0.9"
},
"suggest": {
"cakephp/bake": "Required if you want to generate jobs.",
Expand Down
4 changes: 3 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0"?>
<ruleset name="CakePHP Queue">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />
<rule ref="CakePHP" />

<file>src/</file>
<file>tests/</file>

<exclude-pattern>tests/comparisons/*</exclude-pattern>
</ruleset>
10 changes: 10 additions & 0 deletions src/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ public static function getConfig(string $key): mixed
return static::$_config[$key] ?? null;
}

/**
* Get the configured queue keys.
*
* @return array List of configured queue configuration keys.
*/
public static function configured(): array
{
return array_keys(static::$_config);
}

/**
* Remove a configured queue adapter.
*
Expand Down
20 changes: 10 additions & 10 deletions templates/bake/job.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* @license https://opensource.org/licenses/MIT MIT License
*/
#}
<?php
declare(strict_types=1);

namespace {{ namespace }}\Job;

use Cake\Queue\Job\JobInterface;
use Cake\Queue\Job\Message;
use Interop\Queue\Processor;
{{ element('Bake.file_header', {
namespace: "#{namespace}\\Job",
classImports: [
'Cake\\Queue\\Job\\JobInterface',
'Cake\\Queue\\Job\\Message',
'Interop\\Queue\\Processor',
],
}) }}

/**
* {{ name }} job
Expand All @@ -30,7 +30,7 @@ class {{ name }}Job implements JobInterface
{% if maxAttempts %}
/**
* The maximum number of times the job may be attempted.
*
*
* @var int|null
*/
public static $maxAttempts = {{ maxAttempts }};
Expand All @@ -39,7 +39,7 @@ class {{ name }}Job implements JobInterface
{% if isUnique %}
/**
* Whether there should be only one instance of a job on the queue at a time. (optional property)
*
*
* @var bool
*/
public static $shouldBeUnique = true;
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Command/RequeueCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Cake\Core\Configure;
use Cake\Log\Log;
use Cake\Queue\QueueManager;
use Cake\Queue\Test\TestCase\DebugLogTrait;
use Cake\Queue\Test\TestCase\QueueTestTrait;
use Cake\TestSuite\TestCase;
use TestApp\Job\LogToDebugJob;

Expand All @@ -32,7 +32,7 @@
class RequeueCommandTest extends TestCase
{
use ConsoleIntegrationTestTrait;
use DebugLogTrait;
use QueueTestTrait;

protected array $fixtures = [
'plugin.Cake/Queue.FailedJobs',
Expand Down
57 changes: 22 additions & 35 deletions tests/TestCase/Command/WorkerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @since 0.1.0
* @license https://opensource.org/licenses/MIT MIT License
*/

namespace Cake\Queue\Test\TestCase\Command;

use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
Expand All @@ -22,8 +23,10 @@
use Cake\Queue\QueueManager;
use Cake\Queue\Test\test_app\src\Job\LogToDebugWithServiceJob;
use Cake\Queue\Test\test_app\src\Queue\TestCustomProcessor;
use Cake\Queue\Test\TestCase\DebugLogTrait;
use Cake\Queue\Test\TestCase\QueueTestTrait;
use Cake\TestSuite\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use TestApp\Job\LogToDebugJob;
use TestApp\Job\RequeueJob;
use TestApp\WelcomeMailerListener;
Expand All @@ -36,7 +39,7 @@
class WorkerCommandTest extends TestCase
{
use ConsoleIntegrationTestTrait;
use DebugLogTrait;
use QueueTestTrait;

/**
* Test that command description prints out
Expand All @@ -49,9 +52,8 @@ public function testDescriptionOutput()

/**
* Test that queue will run for one second
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueProcessesStart()
{
Configure::write('Queue', [
Expand All @@ -66,9 +68,8 @@ public function testQueueProcessesStart()

/**
* Test that queue will run for one second with valid listener
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueProcessesWithListener()
{
Configure::write('Queue', [
Expand All @@ -84,9 +85,8 @@ public function testQueueProcessesWithListener()

/**
* Test that queue will abort when the passed config is not present in the app configuration.
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueWillAbortWithMissingConfig()
{
Configure::write('Queue', [
Expand All @@ -103,9 +103,8 @@ public function testQueueWillAbortWithMissingConfig()

/**
* Test that queue will abort with invalid listener
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueProcessesWithInvalidListener()
{
Configure::write('Queue', [
Expand All @@ -122,9 +121,8 @@ public function testQueueProcessesWithInvalidListener()

/**
* Test that queue will write to specified logger option
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueProcessesWithLogger()
{
Configure::write('Queue', [
Expand Down Expand Up @@ -157,10 +155,9 @@ public static function dataProviderCallableTypes(): array

/**
* Start up the worker queue, push a job, and see that it processes
*
* @dataProvider dataProviderCallableTypes
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
#[DataProvider('dataProviderCallableTypes')]
public function testQueueProcessesJob($callable)
{
$config = [
Expand All @@ -186,9 +183,8 @@ public function testQueueProcessesJob($callable)

/**
* Set the processor name, Start up the worker queue, push a job, and see that it processes
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueProcessesJobWithProcessor()
{
$config = [
Expand All @@ -213,9 +209,8 @@ public function testQueueProcessesJobWithProcessor()

/**
* Test non-default queue name
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueProcessesJobWithOtherQueue()
{
$config = [
Expand All @@ -241,9 +236,8 @@ public function testQueueProcessesJobWithOtherQueue()

/**
* Test max-attempts option
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueProcessesJobWithMaxAttempts()
{
$config = [
Expand All @@ -269,9 +263,8 @@ public function testQueueProcessesJobWithMaxAttempts()

/**
* Test DI service injection works in tasks
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueProcessesJobWithDIService()
{
$this->skipIf(version_compare(Configure::version(), '4.2', '<'), 'DI Container is only available since CakePHP 4.2');
Expand All @@ -297,9 +290,8 @@ public function testQueueProcessesJobWithDIService()

/**
* Test that queue will process when a unique cache is configured.
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueProcessesWithUniqueCacheConfigured()
{
$config = [
Expand All @@ -324,9 +316,8 @@ public function testQueueProcessesWithUniqueCacheConfigured()

/**
* Test that queue uses default processor when no processor is specified.
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueUsesDefaultProcessor()
{
$config = [
Expand All @@ -352,9 +343,8 @@ public function testQueueUsesDefaultProcessor()

/**
* Test that queue uses custom processor when specified in configuration.
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueUsesCustomProcessor()
{
$config = [
Expand Down Expand Up @@ -383,9 +373,8 @@ public function testQueueUsesCustomProcessor()

/**
* Test that queue aborts when custom processor class does not exist.
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueAbortsWithNonExistentProcessor()
{
$config = [
Expand All @@ -403,9 +392,8 @@ public function testQueueAbortsWithNonExistentProcessor()

/**
* Test that queue aborts when custom processor does not implement Interop\Queue\Processor.
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testQueueAbortsWithInvalidProcessor()
{
$config = [
Expand All @@ -423,9 +411,8 @@ public function testQueueAbortsWithInvalidProcessor()

/**
* Test that custom processor works with listener configuration.
*
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testCustomProcessorWithListener()
{
$config = [
Expand Down
14 changes: 2 additions & 12 deletions tests/TestCase/Consumption/LimitAttemptsExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Cake\Queue\Consumption\LimitConsumedMessagesExtension;
use Cake\Queue\Queue\Processor as QueueProcessor;
use Cake\Queue\QueueManager;
use Cake\Queue\Test\TestCase\DebugLogTrait;
use Cake\Queue\Test\TestCase\QueueTestTrait;
use Cake\TestSuite\TestCase;
use Enqueue\Consumption\ChainExtension;
use Psr\Log\NullLogger;
Expand All @@ -19,7 +19,7 @@

class LimitAttemptsExtensionTest extends TestCase
{
use DebugLogTrait;
use QueueTestTrait;

public function setUp(): void
{
Expand All @@ -28,16 +28,6 @@ public function setUp(): void
EventManager::instance()->setEventList(new EventList());
}

/**
* @beforeClass
* @after
*/
public static function dropConfigs()
{
Log::drop('debug');
QueueManager::drop('default');
}

public function testMessageShouldBeRequeuedIfMaxAttemptsIsNotSet()
{
$consume = $this->setupQueue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,15 @@
use Cake\Queue\Consumption\RemoveUniqueJobIdFromCacheExtension;
use Cake\Queue\Queue\Processor as QueueProcessor;
use Cake\Queue\QueueManager;
use Cake\Queue\Test\TestCase\QueueTestTrait;
use Cake\TestSuite\TestCase;
use Enqueue\Consumption\ChainExtension;
use Psr\Log\NullLogger;
use TestApp\Job\UniqueJob;

class RemoveUniqueJobIdFromCacheExtensionTest extends TestCase
{
/**
* @beforeClass
* @after
*/
public static function dropConfigs()
{
Log::drop('debug');

QueueManager::drop('default');

$cacheKey = QueueManager::getConfig('default')['uniqueCacheKey'] ?? null;
if ($cacheKey) {
Cache::clear($cacheKey);
Cache::drop($cacheKey);
}
}
use QueueTestTrait;

public function testJobIsRemovedFromCacheAfterProcessing()
{
Expand Down
Loading