Skip to content

Commit 862a7a6

Browse files
authored
Merge pull request #111 from mezzio/renovate/phpunit-phpunit-10.x
Update dependency phpunit/phpunit to v10
2 parents f0ef8d1 + bdcbc5a commit 862a7a6

22 files changed

+579
-566
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/.phpcs-cache
2-
/.phpunit.result.cache
2+
/.phpunit.cache
33
/clover.xml
4-
/coveralls-upload.json
54
/docs/html/
65
/laminas-mkdoc-theme.tgz
76
/laminas-mkdoc-theme/

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"filp/whoops": "^2.15.2",
5555
"laminas/laminas-coding-standard": "~2.5.0",
5656
"laminas/laminas-servicemanager": "^3.20",
57-
"phpunit/phpunit": "9.5.26",
57+
"phpunit/phpunit": "^10.2.2",
5858
"psalm/plugin-phpunit": "^0.18.4",
5959
"swoole/ide-helper": "^5.0.3",
6060
"vimeo/psalm": "^5.12"

composer.lock

Lines changed: 230 additions & 353 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml.dist

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
55
bootstrap="test/bootstrap.php"
6-
convertDeprecationsToExceptions="true"
6+
cacheDirectory=".phpunit.cache"
7+
displayDetailsOnIncompleteTests="true"
8+
displayDetailsOnSkippedTests="true"
9+
displayDetailsOnTestsThatTriggerDeprecations="true"
10+
displayDetailsOnTestsThatTriggerErrors="true"
11+
displayDetailsOnTestsThatTriggerNotices="true"
12+
displayDetailsOnTestsThatTriggerWarnings="true"
713
colors="true">
8-
<coverage processUncoveredFiles="true">
14+
<source>
915
<include>
1016
<directory suffix=".php">./src</directory>
1117
</include>
12-
</coverage>
18+
</source>
1319

1420
<testsuites>
1521
<testsuite name="mezzio-swoole">

test/Command/ReloadCommandTest.php

Lines changed: 48 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Mezzio\Swoole\Command\StartCommand;
1313
use Mezzio\Swoole\Command\StopCommand;
1414
use MezzioTest\Swoole\AttributeAssertionTrait;
15+
use MezzioTest\Swoole\ConsecutiveConstraint;
1516
use PHPUnit\Framework\MockObject\MockObject;
1617
use PHPUnit\Framework\TestCase;
1718
use Symfony\Component\Console\Application;
@@ -155,10 +156,10 @@ public function testExecuteEndsWithErrorWhenStopCommandFails(): void
155156
$this->output
156157
->expects($this->exactly(2))
157158
->method('writeln')
158-
->withConsecutive(
159-
[$this->stringContains('Reloading server')],
160-
[$this->stringContains('Cannot reload server: unable to stop')]
161-
);
159+
->with(new ConsecutiveConstraint([
160+
$this->stringContains('Reloading server'),
161+
$this->stringContains('Cannot reload server: unable to stop'),
162+
]));
162163

163164
$execute = $this->reflectMethod($command, 'execute');
164165
$this->assertSame(1, $execute->invoke($command, $this->input, $this->output));
@@ -171,14 +172,10 @@ public function testExecuteEndsWithErrorWhenStartCommandFails(): void
171172
$this->input
172173
->expects($this->exactly(2))
173174
->method('getOption')
174-
->withConsecutive(
175-
['num-workers'],
176-
['num-task-workers']
177-
)
178-
->willReturnOnConsecutiveCalls(
179-
5,
180-
null
181-
);
175+
->willReturnMap([
176+
['num-workers', 5],
177+
['num-task-workers', null],
178+
]);
182179

183180
$stopCommand = $this->createMock(Command::class);
184181
$stopCommand
@@ -202,38 +199,34 @@ public function testExecuteEndsWithErrorWhenStartCommandFails(): void
202199
$application
203200
->expects($this->exactly(2))
204201
->method('find')
205-
->withConsecutive(
206-
[StopCommand::$defaultName],
207-
[StartCommand::$defaultName]
208-
)
209-
->willReturnOnConsecutiveCalls(
210-
$stopCommand,
211-
$startCommand
212-
);
202+
->willReturnMap([
203+
[StopCommand::$defaultName, $stopCommand],
204+
[StartCommand::$defaultName, $startCommand],
205+
]);
213206

214207
$command->setApplication($application);
215208

216209
$this->output
217210
->expects($this->exactly(4))
218211
->method('writeln')
219-
->withConsecutive(
220-
[$this->stringContains('Reloading server')],
221-
[$this->stringContains('[DONE]')],
222-
[$this->stringContains('Starting server')],
223-
[$this->stringContains('Cannot reload server: unable to start')]
224-
);
212+
->with(new ConsecutiveConstraint([
213+
$this->stringContains('Reloading server'),
214+
$this->stringContains('[DONE]'),
215+
$this->stringContains('Starting server'),
216+
$this->stringContains('Cannot reload server: unable to start'),
217+
]));
225218

226219
$this->output
227220
->expects($this->exactly(6))
228221
->method('write')
229-
->withConsecutive(
230-
[$this->stringContains('Waiting for 5 seconds')],
231-
[$this->stringContains('<info>.</info>')],
232-
[$this->stringContains('<info>.</info>')],
233-
[$this->stringContains('<info>.</info>')],
234-
[$this->stringContains('<info>.</info>')],
235-
[$this->stringContains('<info>.</info>')]
236-
);
222+
->with(new ConsecutiveConstraint([
223+
$this->stringContains('Waiting for 5 seconds'),
224+
$this->stringContains('<info>.</info>'),
225+
$this->stringContains('<info>.</info>'),
226+
$this->stringContains('<info>.</info>'),
227+
$this->stringContains('<info>.</info>'),
228+
$this->stringContains('<info>.</info>'),
229+
]));
237230

238231
$execute = $this->reflectMethod($command, 'execute');
239232
$this->assertSame(1, $execute->invoke($command, $this->input, $this->output));
@@ -246,14 +239,10 @@ public function testExecuteEndsWithSuccessWhenBothStopAndStartCommandsSucceed():
246239
$this->input
247240
->expects($this->exactly(2))
248241
->method('getOption')
249-
->withConsecutive(
250-
['num-workers'],
251-
['num-task-workers']
252-
)
253-
->willReturnOnConsecutiveCalls(
254-
5,
255-
2
256-
);
242+
->willReturnMap([
243+
['num-workers', 5],
244+
['num-task-workers', 2],
245+
]);
257246

258247
$stopCommand = $this->createMock(Command::class);
259248
$stopCommand
@@ -280,35 +269,31 @@ public function testExecuteEndsWithSuccessWhenBothStopAndStartCommandsSucceed():
280269
$application
281270
->expects($this->exactly(2))
282271
->method('find')
283-
->withConsecutive(
284-
[StopCommand::$defaultName],
285-
[StartCommand::$defaultName]
286-
)
287-
->willReturnOnConsecutiveCalls(
288-
$stopCommand,
289-
$startCommand
290-
);
272+
->willReturnMap([
273+
[StopCommand::$defaultName, $stopCommand],
274+
[StartCommand::$defaultName, $startCommand],
275+
]);
291276

292277
$this->output
293278
->expects($this->exactly(3))
294279
->method('writeln')
295-
->withConsecutive(
296-
[$this->stringContains('Reloading server')],
297-
[$this->stringContains('[DONE]')],
298-
[$this->stringContains('Starting server')]
299-
);
280+
->with(new ConsecutiveConstraint([
281+
$this->stringContains('Reloading server'),
282+
$this->stringContains('[DONE]'),
283+
$this->stringContains('Starting server'),
284+
]));
300285

301286
$this->output
302287
->expects($this->exactly(6))
303288
->method('write')
304-
->withConsecutive(
305-
[$this->stringContains('Waiting for 5 seconds')],
306-
[$this->stringContains('<info>.</info>')],
307-
[$this->stringContains('<info>.</info>')],
308-
[$this->stringContains('<info>.</info>')],
309-
[$this->stringContains('<info>.</info>')],
310-
[$this->stringContains('<info>.</info>')]
311-
);
289+
->with(new ConsecutiveConstraint([
290+
$this->stringContains('Waiting for 5 seconds'),
291+
$this->stringContains('<info>.</info>'),
292+
$this->stringContains('<info>.</info>'),
293+
$this->stringContains('<info>.</info>'),
294+
$this->stringContains('<info>.</info>'),
295+
$this->stringContains('<info>.</info>'),
296+
]));
312297

313298
$command->setApplication($application);
314299

test/Command/StopCommandTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Mezzio\Swoole\Command\StopCommand;
1212
use Mezzio\Swoole\PidManager;
1313
use MezzioTest\Swoole\AttributeAssertionTrait;
14+
use MezzioTest\Swoole\ConsecutiveConstraint;
1415
use PHPUnit\Framework\MockObject\MockObject;
1516
use PHPUnit\Framework\TestCase;
1617
use Symfony\Component\Console\Command\Command;
@@ -126,10 +127,10 @@ public function testExecuteReturnsErrorIfUnableToStopServer(array $pids): void
126127
$this->output
127128
->expects($this->exactly(2))
128129
->method('writeln')
129-
->withConsecutive(
130-
[$this->stringContains('Stopping server')],
131-
[$this->stringContains('Error stopping server')]
132-
);
130+
->with(new ConsecutiveConstraint([
131+
$this->stringContains('Stopping server'),
132+
$this->stringContains('Error stopping server'),
133+
]));
133134

134135
$execute = $this->reflectMethod($command, 'execute');
135136

@@ -168,10 +169,10 @@ static function (int $pid) use ($masterPid, $spy): bool {
168169
$this->output
169170
->expects($this->exactly(2))
170171
->method('writeln')
171-
->withConsecutive(
172-
[$this->stringContains('Stopping server')],
173-
[$this->stringContains('Server stopped')]
174-
);
172+
->with(new ConsecutiveConstraint([
173+
$this->stringContains('Stopping server'),
174+
$this->stringContains('Server stopped'),
175+
]));
175176

176177
$execute = $this->reflectMethod($command, 'execute');
177178

test/ConsecutiveConstraint.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MezzioTest\Swoole;
6+
7+
use ArrayIterator;
8+
use Iterator;
9+
use PHPUnit\Framework\Constraint\Constraint;
10+
11+
/**
12+
* PhpUnit 10 removed withConsecutive() without alternative for ordered invocation assertions.
13+
*
14+
* Assertions in willReturnCallback() could potentially be suppressed if
15+
* tested code catches exceptions. Asserting arguments in with() using callback
16+
* has downside in that callback only returns boolean, provides no message, and it can not use
17+
* assertions.
18+
*
19+
* This constraint is stateful and as such it is NOT reusable. Should not be used for new tests.
20+
*/
21+
final class ConsecutiveConstraint extends Constraint
22+
{
23+
/** @var Iterator<array-key, Constraint> */
24+
private Iterator $constraints;
25+
private bool $initial = true;
26+
27+
/**
28+
* @param Constraint[] $consecutive
29+
*/
30+
public function __construct(array $consecutive)
31+
{
32+
$this->constraints = new ArrayIterator($consecutive);
33+
}
34+
35+
protected function matches(mixed $other): bool
36+
{
37+
if (! $this->initial) {
38+
$this->constraints->next();
39+
}
40+
$this->initial = false;
41+
$constraint = $this->constraints->current();
42+
if ($constraint === null) {
43+
return false;
44+
}
45+
/**
46+
* @var bool $return returnResult is set to true.
47+
*/
48+
$return = $constraint->evaluate($other, '', true);
49+
return $return;
50+
}
51+
52+
public function toString(): string
53+
{
54+
$constraint = $this->constraints->current();
55+
if ($constraint === null) {
56+
return 'Consecutive constraints exhausted';
57+
}
58+
/** @psalm-suppress InternalMethod */
59+
return $constraint->toString();
60+
}
61+
}

test/Event/HotCodeReloaderWorkerStartListenerFactoryTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Mezzio\Swoole\HotCodeReload\FileWatcher\InotifyFileWatcher;
1313
use Mezzio\Swoole\HotCodeReload\FileWatcherInterface;
1414
use Mezzio\Swoole\Log\AccessLogInterface;
15+
use MezzioTest\Swoole\ConsecutiveConstraint;
1516
use PHPUnit\Framework\TestCase;
1617
use Psr\Container\ContainerInterface;
1718
use Psr\Log\LoggerInterface;
@@ -42,6 +43,7 @@ public function testProducesHotCodeReloaderListenerWithDefaultConfiguration(): v
4243

4344
public function testProducesHotCodeReloaderListenerUsingIntervalFromConfiguration(): void
4445
{
46+
$this->assertSame(getcwd(), getcwd());
4547
$fileWatcher = $this->createMock(InotifyFileWatcher::class);
4648
$logger = $this->createMock(LoggerInterface::class);
4749
$container = $this->createMock(ContainerInterface::class);
@@ -71,10 +73,10 @@ public function testProducesHotCodeReloaderListenerUsingIntervalFromConfiguratio
7173
$fileWatcher
7274
->expects($this->exactly(2))
7375
->method('addFilePath')
74-
->withConsecutive(
75-
[getcwd()],
76-
[__DIR__]
77-
);
76+
->with(new ConsecutiveConstraint([
77+
$this->identicalTo(getcwd()),
78+
$this->identicalTo(__DIR__),
79+
]));
7880

7981
$factory = new HotCodeReloaderWorkerStartListenerFactory();
8082
$this->assertIsObject($factory($container));

test/Event/RequestHandlerRequestListenerFactoryTest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,12 @@ public function testFactoryProducesListenerUsingServicesFromContainer(): void
3232
$container
3333
->expects($this->exactly(4))
3434
->method('get')
35-
->withConsecutive(
36-
['Mezzio\ApplicationPipeline'],
37-
[ServerRequestInterface::class],
38-
[ServerRequestErrorResponseGenerator::class],
39-
[AccessLogInterface::class]
40-
)
41-
->willReturnOnConsecutiveCalls(
42-
$pipeline,
43-
$requestFactory,
44-
$errorResponseFactory,
45-
$logger
46-
);
35+
->willReturnMap([
36+
['Mezzio\ApplicationPipeline', $pipeline],
37+
[ServerRequestInterface::class, $requestFactory],
38+
[ServerRequestErrorResponseGenerator::class, $errorResponseFactory],
39+
[AccessLogInterface::class, $logger],
40+
]);
4741

4842
$factory = new RequestHandlerRequestListenerFactory();
4943
$this->assertIsObject($factory($container));

test/Event/ServerShutdownListenerFactoryTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@ public function testFactoryProducesListenerUsingServicesFromContainer(): void
2525
$container
2626
->expects($this->exactly(2))
2727
->method('get')
28-
->withConsecutive(
29-
[PidManager::class],
30-
[AccessLogInterface::class]
31-
)
32-
->willReturnOnConsecutiveCalls(
33-
$pidManager,
34-
$logger
35-
);
28+
->willReturnMap([
29+
[PidManager::class, $pidManager],
30+
[AccessLogInterface::class, $logger],
31+
]);
3632

3733
$factory = new ServerShutdownListenerFactory();
3834
$this->assertIsObject($factory($container));

0 commit comments

Comments
 (0)