Skip to content

Commit e8fea96

Browse files
authored
Merge pull request #125 from cakephp/cake5-phpunit10
Cake5: upgrade to PHPUnit 10
2 parents ab29a44 + 9f0d9ed commit e8fea96

File tree

8 files changed

+112
-98
lines changed

8 files changed

+112
-98
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ error.log
1515
/tests/test_app/config/Queue/*
1616
/tests/test_app/config/TestsQueue/schema-dump-test.lock
1717
/tests/test_app/Plugin/TestBlog/config/Queue/*
18-
.phpunit.result.cache
18+
.phpunit.cache
1919

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

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"cakephp/bake": "3.x-dev as 3.0.0",
2828
"cakephp/cakephp-codesniffer": "^5.0",
2929
"enqueue/fs": "^0.10",
30-
"phpunit/phpunit": "^9.5.19"
30+
"phpunit/phpunit": "^10.1.0"
3131
},
3232
"autoload": {
3333
"psr-4": {

phpunit.xml.dist

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
colors="true"
5-
bootstrap="tests/bootstrap.php"
6-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
colors="true"
4+
cacheDirectory=".phpunit.cache"
5+
bootstrap="tests/bootstrap.php"
6+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd">
77
<testsuites>
88
<testsuite name="queue">
99
<directory>tests/TestCase</directory>
1010
</testsuite>
1111
</testsuites>
1212

1313
<extensions>
14-
<extension class="Cake\TestSuite\Fixture\PHPUnitExtension"/>
14+
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
1515
</extensions>
1616

1717
<!-- Only collect coverage for src/ -->
18-
<coverage>
18+
<source>
1919
<include>
2020
<directory suffix=".php">./src/</directory>
2121
</include>
22-
</coverage>
22+
</source>
2323

2424
<php>
2525
<ini name="memory_limit" value="-1"/>

tests/TestCase/Command/WorkerCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testQueueProcessesStart()
6060
],
6161
]);
6262
$this->exec('queue worker --max-runtime=0');
63-
$this->assertEmpty($this->getActualOutput());
63+
$this->assertEmpty($this->output());
6464
}
6565

6666
/**
@@ -78,7 +78,7 @@ public function testQueueProcessesWithListener()
7878
],
7979
]);
8080
$this->exec('queue worker --max-runtime=0');
81-
$this->assertEmpty($this->getActualOutput());
81+
$this->assertEmpty($this->output());
8282
}
8383

8484
/**
@@ -146,7 +146,7 @@ public function testQueueProcessesWithLogger()
146146
*
147147
* @return array
148148
*/
149-
public function dataProviderCallableTypes(): array
149+
public static function dataProviderCallableTypes(): array
150150
{
151151
return [
152152
'Job Class' => [LogToDebugJob::class],

tests/TestCase/Listener/FailedJobsListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function testFailedJobIsAddedWhenEventIsFired()
104104
*
105105
* @return array[]
106106
*/
107-
public function storeFailedJobExceptionDataProvider()
107+
public static function storeFailedJobExceptionDataProvider()
108108
{
109109
return [
110110
[['exception' => 'some message'], '`logger` was not defined on Consumption.LimitAttemptsExtension.failed event'],

tests/TestCase/Queue/ProcessorTest.php

Lines changed: 6 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
use Cake\TestSuite\TestCase;
2525
use Enqueue\Null\NullConnectionFactory;
2626
use Enqueue\Null\NullMessage;
27-
use Exception;
2827
use Interop\Queue\Processor as InteropProcessor;
28+
use TestApp\TestProcessor;
2929

3030
class ProcessorTest extends TestCase
3131
{
@@ -36,7 +36,7 @@ class ProcessorTest extends TestCase
3636
*
3737
* @return array
3838
*/
39-
public function dataProviderTestProcess(): array
39+
public static function dataProviderTestProcess(): array
4040
{
4141
return [
4242
'ack' => ['processReturnAck', InteropProcessor::ACK, 'Message processed sucessfully', 'Processor.message.success'],
@@ -60,7 +60,7 @@ public function dataProviderTestProcess(): array
6060
public function testProcess($jobMethod, $expected, $logMessage, $dispatchedEvent)
6161
{
6262
$messageBody = [
63-
'class' => [static::class, $jobMethod],
63+
'class' => [TestProcessor::class, $jobMethod],
6464
'args' => [],
6565
];
6666
$connectionFactory = new NullConnectionFactory();
@@ -140,7 +140,7 @@ public function testProcessWillRequeueOnException()
140140
{
141141
$method = 'processAndThrowException';
142142
$messageBody = [
143-
'class' => [static::class, $method],
143+
'class' => [TestProcessor::class, $method],
144144
'data' => ['sample_data' => 'a value', 'key' => md5($method)],
145145
];
146146
$connectionFactory = new NullConnectionFactory();
@@ -195,7 +195,7 @@ public function testProcessJobObject()
195195
public function testProcessMessage()
196196
{
197197
$messageBody = [
198-
'class' => [static::class, 'processReturnAck'],
198+
'class' => [TestProcessor::class, 'processReturnAck'],
199199
'args' => [],
200200
];
201201
$connectionFactory = new NullConnectionFactory();
@@ -206,83 +206,6 @@ public function testProcessMessage()
206206

207207
$result = $processor->processMessage($message);
208208
$this->assertSame(InteropProcessor::ACK, $result);
209-
$this->assertNotEmpty(static::$lastProcessMessage);
210-
}
211-
212-
/**
213-
* Job to be used in test testProcessMessageCallableIsString
214-
*
215-
* @param \Cake\Queue\Job\Message $message The message to process
216-
* @return null
217-
*/
218-
public static function processReturnNull(Message $message)
219-
{
220-
static::$lastProcessMessage = $message;
221-
222-
return null;
223-
}
224-
225-
/**
226-
* Job to be used in test testProcessMessageCallableIsString
227-
*
228-
* @param Message $message The message to process
229-
* @return null
230-
* @throws Exception
231-
*/
232-
public static function processAndThrowException(Message $message)
233-
{
234-
throw new Exception('Something went wrong');
235-
}
236-
237-
/**
238-
* Job to be used in test testProcessMessageCallableIsString
239-
*
240-
* @param \Cake\Queue\Message $message The message to process
241-
* @return null
242-
*/
243-
public static function processReturnReject(Message $message)
244-
{
245-
static::$lastProcessMessage = $message;
246-
247-
return InteropProcessor::REJECT;
248-
}
249-
250-
/**
251-
* Job to be used in test testProcessMessageCallableIsString
252-
*
253-
* @param \Cake\Queue\Message $message The message to process
254-
* @return null
255-
*/
256-
public static function processReturnAck(Message $message)
257-
{
258-
static::$lastProcessMessage = $message;
259-
260-
return InteropProcessor::ACK;
261-
}
262-
263-
/**
264-
* Job to be used in test testProcessMessageCallableIsString
265-
*
266-
* @param \Cake\Queue\Message $message The message to process
267-
* @return null
268-
*/
269-
public static function processReturnRequeue(Message $message)
270-
{
271-
static::$lastProcessMessage = $message;
272-
273-
return InteropProcessor::REQUEUE;
274-
}
275-
276-
/**
277-
* Job to be used in test testProcessMessageCallableIsString
278-
*
279-
* @param \Cake\Queue\Message $message The message to process
280-
* @return null
281-
*/
282-
public static function processReturnString(Message $message)
283-
{
284-
static::$lastProcessMessage = $message;
285-
286-
return 'invalid value';
209+
$this->assertNotEmpty(TestProcessor::$lastProcessMessage);
287210
}
288211
}

tests/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use Cake\Cache\Cache;
1919
use Cake\Core\Configure;
20+
use Cake\Datasource\ConnectionManager;
2021
use Cake\Routing\Router;
2122
use Cake\TestSuite\Fixture\SchemaLoader;
2223
use function Cake\Core\env;
@@ -94,7 +95,7 @@
9495
putenv('db_dsn=sqlite:///:memory:');
9596
}
9697

97-
Cake\Datasource\ConnectionManager::setConfig('test', [
98+
ConnectionManager::setConfig('test', [
9899
'url' => getenv('db_dsn'),
99100
'timezone' => 'UTC',
100101
]);
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace TestApp;
5+
6+
use Cake\Queue\Job\Message;
7+
use Exception;
8+
use Interop\Queue\Processor as InteropProcessor;
9+
10+
class TestProcessor
11+
{
12+
public static Message $lastProcessMessage;
13+
14+
/**
15+
* Job to be used in test testProcessMessageCallableIsString
16+
*
17+
* @param Message $message The message to process
18+
* @return null
19+
* @throws Exception
20+
*/
21+
public static function processAndThrowException(Message $message)
22+
{
23+
throw new Exception('Something went wrong');
24+
}
25+
26+
/**
27+
* Job to be used in test testProcessMessageCallableIsString
28+
*
29+
* @param \Cake\Queue\Message $message The message to process
30+
* @return null
31+
*/
32+
public static function processReturnAck(Message $message)
33+
{
34+
static::$lastProcessMessage = $message;
35+
36+
return InteropProcessor::ACK;
37+
}
38+
39+
/**
40+
* Job to be used in test testProcessMessageCallableIsString
41+
*
42+
* @param \Cake\Queue\Job\Message $message The message to process
43+
* @return null
44+
*/
45+
public static function processReturnNull(Message $message)
46+
{
47+
static::$lastProcessMessage = $message;
48+
49+
return null;
50+
}
51+
52+
/**
53+
* Job to be used in test testProcessMessageCallableIsString
54+
*
55+
* @param \Cake\Queue\Message $message The message to process
56+
* @return null
57+
*/
58+
public static function processReturnReject(Message $message)
59+
{
60+
static::$lastProcessMessage = $message;
61+
62+
return InteropProcessor::REJECT;
63+
}
64+
65+
/**
66+
* Job to be used in test testProcessMessageCallableIsString
67+
*
68+
* @param \Cake\Queue\Message $message The message to process
69+
* @return null
70+
*/
71+
public static function processReturnRequeue(Message $message)
72+
{
73+
static::$lastProcessMessage = $message;
74+
75+
return InteropProcessor::REQUEUE;
76+
}
77+
78+
/**
79+
* Job to be used in test testProcessMessageCallableIsString
80+
*
81+
* @param \Cake\Queue\Message $message The message to process
82+
* @return null
83+
*/
84+
public static function processReturnString(Message $message)
85+
{
86+
static::$lastProcessMessage = $message;
87+
88+
return 'invalid value';
89+
}
90+
}

0 commit comments

Comments
 (0)