Skip to content

Commit f19385d

Browse files
committed
Merge branch '2.x' into 2.next
2 parents 9aed2de + c1f38ee commit f19385d

22 files changed

+2431
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/tags
66
/composer.lock
77
/phpunit.xml
8-
/phpcs.xml
98
/tools
109
/vendor
1110
*.mo
@@ -16,6 +15,7 @@ error.log
1615
/tests/test_app/config/TestsQueue/schema-dump-test.lock
1716
/tests/test_app/Plugin/TestBlog/config/Queue/*
1817
.phpunit.cache
18+
.phpcs.cache
1919

2020
# IDE and editor specific files #
2121
#################################

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
"@cs-check",
6161
"@test"
6262
],
63-
"cs-check": "phpcs --colors -p src/ tests/",
64-
"cs-fix": "phpcbf --colors -p src/ tests/",
63+
"cs-check": "phpcs",
64+
"cs-fix": "phpcbf",
6565
"stan": "@phpstan",
6666
"phpstan": "tools/phpstan analyse",
6767
"stan-baseline": "tools/phpstan --generate-baseline",

phpcs.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="CakePHP PluginInstaller">
3+
<file>src/</file>
4+
<file>tests/</file>
5+
<rule ref="CakePHP" />
6+
<arg value="nps"/>
7+
<arg name="colors"/>
8+
<arg name="parallel" value="4"/>
9+
<arg name="cache" value=".phpcs.cache"/>
10+
11+
<exclude-pattern>tests/comparisons/*</exclude-pattern>
12+
</ruleset>

rector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
DocblockReturnArrayFromDirectArrayInstanceRector::class => [
2626
__DIR__ . '/src/Mailer/Transport/QueueTransport.php',
2727
],
28+
'tests/TestCase/Queue/ProcessorTest.php',
2829
])
2930
->withParallel()
3031
->withPreparedSets(

src/Job/SendMailJob.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public function execute(Message $message): ?string
3838
try {
3939
$transportClassName = $message->getArgument('transport');
4040
$config = $message->getArgument('config', []);
41-
/** @var \Cake\Mailer\AbstractTransport $transport */
4241
$transport = $this->getTransport($transportClassName, $config);
4342

4443
$emailMessage = new MailerMessage();
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Cake\Queue\TestSuite\Constraint\Queue;
5+
6+
use Cake\Queue\TestSuite\TestQueueClient;
7+
8+
/**
9+
* JobCount
10+
*
11+
* Asserts that a specific count of jobs were queued
12+
*
13+
* @internal
14+
*/
15+
class JobCount extends QueueConstraintBase
16+
{
17+
/**
18+
* Checks if job count matches
19+
*
20+
* @param mixed $other Expected count
21+
* @return bool
22+
*/
23+
public function matches(mixed $other): bool
24+
{
25+
$expectedCount = $other;
26+
$actualCount = TestQueueClient::getQueuedJobCount();
27+
28+
return $actualCount === $expectedCount;
29+
}
30+
31+
/**
32+
* Assertion message
33+
*
34+
* @return string
35+
*/
36+
public function toString(): string
37+
{
38+
return 'job count matches';
39+
}
40+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Cake\Queue\TestSuite\Constraint\Queue;
5+
6+
/**
7+
* JobQueued
8+
*
9+
* Asserts that a job of a specific class was queued
10+
*
11+
* @internal
12+
*/
13+
class JobQueued extends QueueConstraintBase
14+
{
15+
/**
16+
* Checks if job was queued
17+
*
18+
* @param mixed $other Job class name
19+
* @return bool
20+
*/
21+
public function matches(mixed $other): bool
22+
{
23+
$jobClass = $other;
24+
$jobs = $this->getJobs();
25+
26+
foreach ($jobs as $job) {
27+
if ($job['jobClass'] === $jobClass) {
28+
return true;
29+
}
30+
}
31+
32+
return false;
33+
}
34+
35+
/**
36+
* Assertion message
37+
*
38+
* @return string
39+
*/
40+
public function toString(): string
41+
{
42+
if ($this->at !== null) {
43+
return sprintf('job #%d was queued', $this->at);
44+
}
45+
46+
return 'job was queued';
47+
}
48+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Cake\Queue\TestSuite\Constraint\Queue;
5+
6+
use Cake\Queue\TestSuite\TestQueueClient;
7+
8+
/**
9+
* JobQueuedTimes
10+
*
11+
* Asserts that a job was queued a specific number of times
12+
*
13+
* @internal
14+
*/
15+
class JobQueuedTimes extends QueueConstraintBase
16+
{
17+
/**
18+
* Expected number of times
19+
*
20+
* @var int
21+
*/
22+
protected int $times;
23+
24+
/**
25+
* Constructor
26+
*
27+
* @param int $times Expected number of times
28+
*/
29+
public function __construct(int $times)
30+
{
31+
$this->times = $times;
32+
}
33+
34+
/**
35+
* Checks if job was queued the expected number of times
36+
*
37+
* @param mixed $other Job class name
38+
* @return bool
39+
*/
40+
public function matches(mixed $other): bool
41+
{
42+
$jobClass = $other;
43+
$jobs = TestQueueClient::getQueuedJobsByClass($jobClass);
44+
$actualCount = count($jobs);
45+
46+
return $actualCount === $this->times;
47+
}
48+
49+
/**
50+
* Assertion message
51+
*
52+
* @return string
53+
*/
54+
public function toString(): string
55+
{
56+
return sprintf('job was queued %d times', $this->times);
57+
}
58+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Cake\Queue\TestSuite\Constraint\Queue;
5+
6+
use Cake\Queue\TestSuite\TestQueueClient;
7+
8+
/**
9+
* NoJobQueued
10+
*
11+
* Asserts that no jobs were queued
12+
*
13+
* @internal
14+
*/
15+
class NoJobQueued extends QueueConstraintBase
16+
{
17+
/**
18+
* Checks if no jobs were queued
19+
*
20+
* @param mixed $other Ignored
21+
* @return bool
22+
*/
23+
public function matches(mixed $other): bool
24+
{
25+
return TestQueueClient::getQueuedJobCount() === 0;
26+
}
27+
28+
/**
29+
* Assertion message
30+
*
31+
* @return string
32+
*/
33+
public function toString(): string
34+
{
35+
return 'no jobs were queued';
36+
}
37+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Cake\Queue\TestSuite\Constraint\Queue;
5+
6+
use Cake\Queue\TestSuite\TestQueueClient;
7+
use PHPUnit\Framework\Constraint\Constraint;
8+
9+
/**
10+
* Base class for all queue assertion constraints
11+
*
12+
* @internal
13+
*/
14+
abstract class QueueConstraintBase extends Constraint
15+
{
16+
/**
17+
* Job index to check
18+
*
19+
* @var int|null
20+
*/
21+
protected ?int $at = null;
22+
23+
/**
24+
* Constructor
25+
*
26+
* @param int|null $at Optional index of specific job to check
27+
*/
28+
public function __construct(?int $at = null)
29+
{
30+
$this->at = $at;
31+
}
32+
33+
/**
34+
* Get the jobs or job to check
35+
*
36+
* @return array<array<string, mixed>>
37+
*/
38+
protected function getJobs(): array
39+
{
40+
$jobs = TestQueueClient::getQueuedJobs();
41+
42+
if ($this->at !== null) {
43+
if (!isset($jobs[$this->at])) {
44+
return [];
45+
}
46+
47+
return [$jobs[$this->at]];
48+
}
49+
50+
return $jobs;
51+
}
52+
}

0 commit comments

Comments
 (0)