Skip to content

Commit acfc65b

Browse files
authored
Merge pull request #174 from cakephp/ci
Fix CI errors
2 parents aaa0b2c + 8c31f73 commit acfc65b

19 files changed

+194
-133
lines changed

.phive/phars.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
3-
<phar name="phpstan" version="2.1.17" installed="2.1.17" location="./tools/phpstan" copy="false"/>
3+
<phar name="phpstan" version="2.1.31" installed="2.1.31" location="./tools/phpstan" copy="false"/>
44
</phive>

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
},
2323
"require": {
2424
"php": ">=8.1",
25-
"cakephp/cakephp": "^5.0.0",
25+
"cakephp/cakephp": "^5.1.0",
2626
"enqueue/simple-client": "^0.10",
2727
"psr/log": "^3.0"
2828
},
2929
"require-dev": {
30-
"cakephp/bake": "^3.0.0",
30+
"cakephp/bake": "^3.5.1",
3131
"cakephp/cakephp-codesniffer": "^5.0",
3232
"enqueue/fs": "^0.10",
33-
"phpunit/phpunit": "^10.1.0"
33+
"phpunit/phpunit": "^10.5.32 || ^11.3.3 || ^12.0.9"
3434
},
3535
"suggest": {
3636
"cakephp/bake": "Required if you want to generate jobs.",

phpcs.xml.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?xml version="1.0"?>
22
<ruleset name="CakePHP Queue">
3-
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />
43
<rule ref="CakePHP" />
54

5+
<file>src/</file>
6+
<file>tests/</file>
7+
68
<exclude-pattern>tests/comparisons/*</exclude-pattern>
79
</ruleset>

src/QueueManager.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ public static function getConfig(string $key): mixed
147147
return static::$_config[$key] ?? null;
148148
}
149149

150+
/**
151+
* Get the configured queue keys.
152+
*
153+
* @return array List of configured queue configuration keys.
154+
*/
155+
public static function configured(): array
156+
{
157+
return array_keys(static::$_config);
158+
}
159+
150160
/**
151161
* Remove a configured queue adapter.
152162
*

templates/bake/job.twig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
* @license https://opensource.org/licenses/MIT MIT License
1414
*/
1515
#}
16-
<?php
17-
declare(strict_types=1);
18-
19-
namespace {{ namespace }}\Job;
20-
21-
use Cake\Queue\Job\JobInterface;
22-
use Cake\Queue\Job\Message;
23-
use Interop\Queue\Processor;
16+
{{ element('Bake.file_header', {
17+
namespace: "#{namespace}\\Job",
18+
classImports: [
19+
'Cake\\Queue\\Job\\JobInterface',
20+
'Cake\\Queue\\Job\\Message',
21+
'Interop\\Queue\\Processor',
22+
],
23+
}) }}
2424

2525
/**
2626
* {{ name }} job
@@ -30,7 +30,7 @@ class {{ name }}Job implements JobInterface
3030
{% if maxAttempts %}
3131
/**
3232
* The maximum number of times the job may be attempted.
33-
*
33+
*
3434
* @var int|null
3535
*/
3636
public static $maxAttempts = {{ maxAttempts }};
@@ -39,7 +39,7 @@ class {{ name }}Job implements JobInterface
3939
{% if isUnique %}
4040
/**
4141
* Whether there should be only one instance of a job on the queue at a time. (optional property)
42-
*
42+
*
4343
* @var bool
4444
*/
4545
public static $shouldBeUnique = true;

tests/TestCase/Command/RequeueCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Cake\Core\Configure;
2121
use Cake\Log\Log;
2222
use Cake\Queue\QueueManager;
23-
use Cake\Queue\Test\TestCase\DebugLogTrait;
23+
use Cake\Queue\Test\TestCase\QueueTestTrait;
2424
use Cake\TestSuite\TestCase;
2525
use TestApp\Job\LogToDebugJob;
2626

@@ -32,7 +32,7 @@
3232
class RequeueCommandTest extends TestCase
3333
{
3434
use ConsoleIntegrationTestTrait;
35-
use DebugLogTrait;
35+
use QueueTestTrait;
3636

3737
protected array $fixtures = [
3838
'plugin.Cake/Queue.FailedJobs',

tests/TestCase/Command/WorkerCommandTest.php

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @since 0.1.0
1515
* @license https://opensource.org/licenses/MIT MIT License
1616
*/
17+
1718
namespace Cake\Queue\Test\TestCase\Command;
1819

1920
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
@@ -22,8 +23,10 @@
2223
use Cake\Queue\QueueManager;
2324
use Cake\Queue\Test\test_app\src\Job\LogToDebugWithServiceJob;
2425
use Cake\Queue\Test\test_app\src\Queue\TestCustomProcessor;
25-
use Cake\Queue\Test\TestCase\DebugLogTrait;
26+
use Cake\Queue\Test\TestCase\QueueTestTrait;
2627
use Cake\TestSuite\TestCase;
28+
use PHPUnit\Framework\Attributes\DataProvider;
29+
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
2730
use TestApp\Job\LogToDebugJob;
2831
use TestApp\Job\RequeueJob;
2932
use TestApp\WelcomeMailerListener;
@@ -36,7 +39,7 @@
3639
class WorkerCommandTest extends TestCase
3740
{
3841
use ConsoleIntegrationTestTrait;
39-
use DebugLogTrait;
42+
use QueueTestTrait;
4043

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

5053
/**
5154
* Test that queue will run for one second
52-
*
53-
* @runInSeparateProcess
5455
*/
56+
#[RunInSeparateProcess]
5557
public function testQueueProcessesStart()
5658
{
5759
Configure::write('Queue', [
@@ -66,9 +68,8 @@ public function testQueueProcessesStart()
6668

6769
/**
6870
* Test that queue will run for one second with valid listener
69-
*
70-
* @runInSeparateProcess
7171
*/
72+
#[RunInSeparateProcess]
7273
public function testQueueProcessesWithListener()
7374
{
7475
Configure::write('Queue', [
@@ -84,9 +85,8 @@ public function testQueueProcessesWithListener()
8485

8586
/**
8687
* Test that queue will abort when the passed config is not present in the app configuration.
87-
*
88-
* @runInSeparateProcess
8988
*/
89+
#[RunInSeparateProcess]
9090
public function testQueueWillAbortWithMissingConfig()
9191
{
9292
Configure::write('Queue', [
@@ -103,9 +103,8 @@ public function testQueueWillAbortWithMissingConfig()
103103

104104
/**
105105
* Test that queue will abort with invalid listener
106-
*
107-
* @runInSeparateProcess
108106
*/
107+
#[RunInSeparateProcess]
109108
public function testQueueProcessesWithInvalidListener()
110109
{
111110
Configure::write('Queue', [
@@ -122,9 +121,8 @@ public function testQueueProcessesWithInvalidListener()
122121

123122
/**
124123
* Test that queue will write to specified logger option
125-
*
126-
* @runInSeparateProcess
127124
*/
125+
#[RunInSeparateProcess]
128126
public function testQueueProcessesWithLogger()
129127
{
130128
Configure::write('Queue', [
@@ -157,10 +155,9 @@ public static function dataProviderCallableTypes(): array
157155

158156
/**
159157
* Start up the worker queue, push a job, and see that it processes
160-
*
161-
* @dataProvider dataProviderCallableTypes
162-
* @runInSeparateProcess
163158
*/
159+
#[RunInSeparateProcess]
160+
#[DataProvider('dataProviderCallableTypes')]
164161
public function testQueueProcessesJob($callable)
165162
{
166163
$config = [
@@ -186,9 +183,8 @@ public function testQueueProcessesJob($callable)
186183

187184
/**
188185
* Set the processor name, Start up the worker queue, push a job, and see that it processes
189-
*
190-
* @runInSeparateProcess
191186
*/
187+
#[RunInSeparateProcess]
192188
public function testQueueProcessesJobWithProcessor()
193189
{
194190
$config = [
@@ -213,9 +209,8 @@ public function testQueueProcessesJobWithProcessor()
213209

214210
/**
215211
* Test non-default queue name
216-
*
217-
* @runInSeparateProcess
218212
*/
213+
#[RunInSeparateProcess]
219214
public function testQueueProcessesJobWithOtherQueue()
220215
{
221216
$config = [
@@ -241,9 +236,8 @@ public function testQueueProcessesJobWithOtherQueue()
241236

242237
/**
243238
* Test max-attempts option
244-
*
245-
* @runInSeparateProcess
246239
*/
240+
#[RunInSeparateProcess]
247241
public function testQueueProcessesJobWithMaxAttempts()
248242
{
249243
$config = [
@@ -269,9 +263,8 @@ public function testQueueProcessesJobWithMaxAttempts()
269263

270264
/**
271265
* Test DI service injection works in tasks
272-
*
273-
* @runInSeparateProcess
274266
*/
267+
#[RunInSeparateProcess]
275268
public function testQueueProcessesJobWithDIService()
276269
{
277270
$this->skipIf(version_compare(Configure::version(), '4.2', '<'), 'DI Container is only available since CakePHP 4.2');
@@ -297,9 +290,8 @@ public function testQueueProcessesJobWithDIService()
297290

298291
/**
299292
* Test that queue will process when a unique cache is configured.
300-
*
301-
* @runInSeparateProcess
302293
*/
294+
#[RunInSeparateProcess]
303295
public function testQueueProcessesWithUniqueCacheConfigured()
304296
{
305297
$config = [
@@ -324,9 +316,8 @@ public function testQueueProcessesWithUniqueCacheConfigured()
324316

325317
/**
326318
* Test that queue uses default processor when no processor is specified.
327-
*
328-
* @runInSeparateProcess
329319
*/
320+
#[RunInSeparateProcess]
330321
public function testQueueUsesDefaultProcessor()
331322
{
332323
$config = [
@@ -352,9 +343,8 @@ public function testQueueUsesDefaultProcessor()
352343

353344
/**
354345
* Test that queue uses custom processor when specified in configuration.
355-
*
356-
* @runInSeparateProcess
357346
*/
347+
#[RunInSeparateProcess]
358348
public function testQueueUsesCustomProcessor()
359349
{
360350
$config = [
@@ -383,9 +373,8 @@ public function testQueueUsesCustomProcessor()
383373

384374
/**
385375
* Test that queue aborts when custom processor class does not exist.
386-
*
387-
* @runInSeparateProcess
388376
*/
377+
#[RunInSeparateProcess]
389378
public function testQueueAbortsWithNonExistentProcessor()
390379
{
391380
$config = [
@@ -403,9 +392,8 @@ public function testQueueAbortsWithNonExistentProcessor()
403392

404393
/**
405394
* Test that queue aborts when custom processor does not implement Interop\Queue\Processor.
406-
*
407-
* @runInSeparateProcess
408395
*/
396+
#[RunInSeparateProcess]
409397
public function testQueueAbortsWithInvalidProcessor()
410398
{
411399
$config = [
@@ -423,9 +411,8 @@ public function testQueueAbortsWithInvalidProcessor()
423411

424412
/**
425413
* Test that custom processor works with listener configuration.
426-
*
427-
* @runInSeparateProcess
428414
*/
415+
#[RunInSeparateProcess]
429416
public function testCustomProcessorWithListener()
430417
{
431418
$config = [

tests/TestCase/Consumption/LimitAttemptsExtensionTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Cake\Queue\Consumption\LimitConsumedMessagesExtension;
1111
use Cake\Queue\Queue\Processor as QueueProcessor;
1212
use Cake\Queue\QueueManager;
13-
use Cake\Queue\Test\TestCase\DebugLogTrait;
13+
use Cake\Queue\Test\TestCase\QueueTestTrait;
1414
use Cake\TestSuite\TestCase;
1515
use Enqueue\Consumption\ChainExtension;
1616
use Psr\Log\NullLogger;
@@ -19,7 +19,7 @@
1919

2020
class LimitAttemptsExtensionTest extends TestCase
2121
{
22-
use DebugLogTrait;
22+
use QueueTestTrait;
2323

2424
public function setUp(): void
2525
{
@@ -28,16 +28,6 @@ public function setUp(): void
2828
EventManager::instance()->setEventList(new EventList());
2929
}
3030

31-
/**
32-
* @beforeClass
33-
* @after
34-
*/
35-
public static function dropConfigs()
36-
{
37-
Log::drop('debug');
38-
QueueManager::drop('default');
39-
}
40-
4131
public function testMessageShouldBeRequeuedIfMaxAttemptsIsNotSet()
4232
{
4333
$consume = $this->setupQueue();

tests/TestCase/Consumption/RemoveUniqueJobIdFromCacheExtensionTest.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,15 @@
99
use Cake\Queue\Consumption\RemoveUniqueJobIdFromCacheExtension;
1010
use Cake\Queue\Queue\Processor as QueueProcessor;
1111
use Cake\Queue\QueueManager;
12+
use Cake\Queue\Test\TestCase\QueueTestTrait;
1213
use Cake\TestSuite\TestCase;
1314
use Enqueue\Consumption\ChainExtension;
1415
use Psr\Log\NullLogger;
1516
use TestApp\Job\UniqueJob;
1617

1718
class RemoveUniqueJobIdFromCacheExtensionTest extends TestCase
1819
{
19-
/**
20-
* @beforeClass
21-
* @after
22-
*/
23-
public static function dropConfigs()
24-
{
25-
Log::drop('debug');
26-
27-
QueueManager::drop('default');
28-
29-
$cacheKey = QueueManager::getConfig('default')['uniqueCacheKey'] ?? null;
30-
if ($cacheKey) {
31-
Cache::clear($cacheKey);
32-
Cache::drop($cacheKey);
33-
}
34-
}
20+
use QueueTestTrait;
3521

3622
public function testJobIsRemovedFromCacheAfterProcessing()
3723
{

0 commit comments

Comments
 (0)