Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependency phpunit/phpunit to v10 #111

Merged
merged 4 commits into from
Jun 14, 2023
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/.phpcs-cache
/.phpunit.result.cache
/.phpunit.cache
/clover.xml
/coveralls-upload.json
/docs/html/
/laminas-mkdoc-theme.tgz
/laminas-mkdoc-theme/
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"filp/whoops": "^2.15.2",
"laminas/laminas-coding-standard": "~2.5.0",
"laminas/laminas-servicemanager": "^3.20",
"phpunit/phpunit": "9.5.26",
"phpunit/phpunit": "^10.2.2",
"psalm/plugin-phpunit": "^0.18.4",
"swoole/ide-helper": "^5.0.3",
"vimeo/psalm": "^5.12"
Expand Down
583 changes: 230 additions & 353 deletions composer.lock

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="test/bootstrap.php"
convertDeprecationsToExceptions="true"
cacheDirectory=".phpunit.cache"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
colors="true">
<coverage processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</source>

<testsuites>
<testsuite name="mezzio-swoole">
Expand Down
111 changes: 48 additions & 63 deletions test/Command/ReloadCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Mezzio\Swoole\Command\StartCommand;
use Mezzio\Swoole\Command\StopCommand;
use MezzioTest\Swoole\AttributeAssertionTrait;
use MezzioTest\Swoole\ConsecutiveConstraint;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -155,10 +156,10 @@ public function testExecuteEndsWithErrorWhenStopCommandFails(): void
$this->output
->expects($this->exactly(2))
->method('writeln')
->withConsecutive(
[$this->stringContains('Reloading server')],
[$this->stringContains('Cannot reload server: unable to stop')]
);
->with(new ConsecutiveConstraint([
$this->stringContains('Reloading server'),
$this->stringContains('Cannot reload server: unable to stop'),
]));

$execute = $this->reflectMethod($command, 'execute');
$this->assertSame(1, $execute->invoke($command, $this->input, $this->output));
Expand All @@ -171,14 +172,10 @@ public function testExecuteEndsWithErrorWhenStartCommandFails(): void
$this->input
->expects($this->exactly(2))
->method('getOption')
->withConsecutive(
['num-workers'],
['num-task-workers']
)
->willReturnOnConsecutiveCalls(
5,
null
);
->willReturnMap([
['num-workers', 5],
['num-task-workers', null],
]);

$stopCommand = $this->createMock(Command::class);
$stopCommand
Expand All @@ -202,38 +199,34 @@ public function testExecuteEndsWithErrorWhenStartCommandFails(): void
$application
->expects($this->exactly(2))
->method('find')
->withConsecutive(
[StopCommand::$defaultName],
[StartCommand::$defaultName]
)
->willReturnOnConsecutiveCalls(
$stopCommand,
$startCommand
);
->willReturnMap([
[StopCommand::$defaultName, $stopCommand],
[StartCommand::$defaultName, $startCommand],
]);

$command->setApplication($application);

$this->output
->expects($this->exactly(4))
->method('writeln')
->withConsecutive(
[$this->stringContains('Reloading server')],
[$this->stringContains('[DONE]')],
[$this->stringContains('Starting server')],
[$this->stringContains('Cannot reload server: unable to start')]
);
->with(new ConsecutiveConstraint([
$this->stringContains('Reloading server'),
$this->stringContains('[DONE]'),
$this->stringContains('Starting server'),
$this->stringContains('Cannot reload server: unable to start'),
]));

$this->output
->expects($this->exactly(6))
->method('write')
->withConsecutive(
[$this->stringContains('Waiting for 5 seconds')],
[$this->stringContains('<info>.</info>')],
[$this->stringContains('<info>.</info>')],
[$this->stringContains('<info>.</info>')],
[$this->stringContains('<info>.</info>')],
[$this->stringContains('<info>.</info>')]
);
->with(new ConsecutiveConstraint([
$this->stringContains('Waiting for 5 seconds'),
$this->stringContains('<info>.</info>'),
$this->stringContains('<info>.</info>'),
$this->stringContains('<info>.</info>'),
$this->stringContains('<info>.</info>'),
$this->stringContains('<info>.</info>'),
]));

$execute = $this->reflectMethod($command, 'execute');
$this->assertSame(1, $execute->invoke($command, $this->input, $this->output));
Expand All @@ -246,14 +239,10 @@ public function testExecuteEndsWithSuccessWhenBothStopAndStartCommandsSucceed():
$this->input
->expects($this->exactly(2))
->method('getOption')
->withConsecutive(
['num-workers'],
['num-task-workers']
)
->willReturnOnConsecutiveCalls(
5,
2
);
->willReturnMap([
['num-workers', 5],
['num-task-workers', 2],
]);

$stopCommand = $this->createMock(Command::class);
$stopCommand
Expand All @@ -280,35 +269,31 @@ public function testExecuteEndsWithSuccessWhenBothStopAndStartCommandsSucceed():
$application
->expects($this->exactly(2))
->method('find')
->withConsecutive(
[StopCommand::$defaultName],
[StartCommand::$defaultName]
)
->willReturnOnConsecutiveCalls(
$stopCommand,
$startCommand
);
->willReturnMap([
[StopCommand::$defaultName, $stopCommand],
[StartCommand::$defaultName, $startCommand],
]);

$this->output
->expects($this->exactly(3))
->method('writeln')
->withConsecutive(
[$this->stringContains('Reloading server')],
[$this->stringContains('[DONE]')],
[$this->stringContains('Starting server')]
);
->with(new ConsecutiveConstraint([
$this->stringContains('Reloading server'),
$this->stringContains('[DONE]'),
$this->stringContains('Starting server'),
]));

$this->output
->expects($this->exactly(6))
->method('write')
->withConsecutive(
[$this->stringContains('Waiting for 5 seconds')],
[$this->stringContains('<info>.</info>')],
[$this->stringContains('<info>.</info>')],
[$this->stringContains('<info>.</info>')],
[$this->stringContains('<info>.</info>')],
[$this->stringContains('<info>.</info>')]
);
->with(new ConsecutiveConstraint([
$this->stringContains('Waiting for 5 seconds'),
$this->stringContains('<info>.</info>'),
$this->stringContains('<info>.</info>'),
$this->stringContains('<info>.</info>'),
$this->stringContains('<info>.</info>'),
$this->stringContains('<info>.</info>'),
]));

$command->setApplication($application);

Expand Down
17 changes: 9 additions & 8 deletions test/Command/StopCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Mezzio\Swoole\Command\StopCommand;
use Mezzio\Swoole\PidManager;
use MezzioTest\Swoole\AttributeAssertionTrait;
use MezzioTest\Swoole\ConsecutiveConstraint;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -126,10 +127,10 @@ public function testExecuteReturnsErrorIfUnableToStopServer(array $pids): void
$this->output
->expects($this->exactly(2))
->method('writeln')
->withConsecutive(
[$this->stringContains('Stopping server')],
[$this->stringContains('Error stopping server')]
);
->with(new ConsecutiveConstraint([
$this->stringContains('Stopping server'),
$this->stringContains('Error stopping server'),
]));

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

Expand Down Expand Up @@ -168,10 +169,10 @@ static function (int $pid) use ($masterPid, $spy): bool {
$this->output
->expects($this->exactly(2))
->method('writeln')
->withConsecutive(
[$this->stringContains('Stopping server')],
[$this->stringContains('Server stopped')]
);
->with(new ConsecutiveConstraint([
$this->stringContains('Stopping server'),
$this->stringContains('Server stopped'),
]));

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

Expand Down
61 changes: 61 additions & 0 deletions test/ConsecutiveConstraint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace MezzioTest\Swoole;

use ArrayIterator;
use Iterator;
use PHPUnit\Framework\Constraint\Constraint;

/**
* PhpUnit 10 removed withConsecutive() without alternative for ordered invocation assertions.
*
* Assertions in willReturnCallback() could potentially be suppressed if
* tested code catches exceptions. Asserting arguments in with() using callback
* has downside in that callback only returns boolean, provides no message, and it can not use
* assertions.
*
* This constraint is stateful and as such it is NOT reusable. Should not be used for new tests.
*/
final class ConsecutiveConstraint extends Constraint
{
/** @var Iterator<array-key, Constraint> */
private Iterator $constraints;
private bool $initial = true;

/**
* @param Constraint[] $consecutive
*/
public function __construct(array $consecutive)
{
$this->constraints = new ArrayIterator($consecutive);
}

protected function matches(mixed $other): bool
{
if (! $this->initial) {
$this->constraints->next();
}
$this->initial = false;
$constraint = $this->constraints->current();
if ($constraint === null) {
return false;
}
/**
* @var bool $return returnResult is set to true.
*/
$return = $constraint->evaluate($other, '', true);
return $return;
}

public function toString(): string
{
$constraint = $this->constraints->current();
if ($constraint === null) {
return 'Consecutive constraints exhausted';
}
/** @psalm-suppress InternalMethod */
return $constraint->toString();
}
}
10 changes: 6 additions & 4 deletions test/Event/HotCodeReloaderWorkerStartListenerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Mezzio\Swoole\HotCodeReload\FileWatcher\InotifyFileWatcher;
use Mezzio\Swoole\HotCodeReload\FileWatcherInterface;
use Mezzio\Swoole\Log\AccessLogInterface;
use MezzioTest\Swoole\ConsecutiveConstraint;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -42,6 +43,7 @@ public function testProducesHotCodeReloaderListenerWithDefaultConfiguration(): v

public function testProducesHotCodeReloaderListenerUsingIntervalFromConfiguration(): void
{
$this->assertSame(getcwd(), getcwd());
$fileWatcher = $this->createMock(InotifyFileWatcher::class);
$logger = $this->createMock(LoggerInterface::class);
$container = $this->createMock(ContainerInterface::class);
Expand Down Expand Up @@ -71,10 +73,10 @@ public function testProducesHotCodeReloaderListenerUsingIntervalFromConfiguratio
$fileWatcher
->expects($this->exactly(2))
->method('addFilePath')
->withConsecutive(
[getcwd()],
[__DIR__]
);
->with(new ConsecutiveConstraint([
$this->identicalTo(getcwd()),
$this->identicalTo(__DIR__),
]));

$factory = new HotCodeReloaderWorkerStartListenerFactory();
$this->assertIsObject($factory($container));
Expand Down
18 changes: 6 additions & 12 deletions test/Event/RequestHandlerRequestListenerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,12 @@ public function testFactoryProducesListenerUsingServicesFromContainer(): void
$container
->expects($this->exactly(4))
->method('get')
->withConsecutive(
['Mezzio\ApplicationPipeline'],
[ServerRequestInterface::class],
[ServerRequestErrorResponseGenerator::class],
[AccessLogInterface::class]
)
->willReturnOnConsecutiveCalls(
$pipeline,
$requestFactory,
$errorResponseFactory,
$logger
);
->willReturnMap([
['Mezzio\ApplicationPipeline', $pipeline],
[ServerRequestInterface::class, $requestFactory],
[ServerRequestErrorResponseGenerator::class, $errorResponseFactory],
[AccessLogInterface::class, $logger],
]);

$factory = new RequestHandlerRequestListenerFactory();
$this->assertIsObject($factory($container));
Expand Down
12 changes: 4 additions & 8 deletions test/Event/ServerShutdownListenerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ public function testFactoryProducesListenerUsingServicesFromContainer(): void
$container
->expects($this->exactly(2))
->method('get')
->withConsecutive(
[PidManager::class],
[AccessLogInterface::class]
)
->willReturnOnConsecutiveCalls(
$pidManager,
$logger
);
->willReturnMap([
[PidManager::class, $pidManager],
[AccessLogInterface::class, $logger],
]);

$factory = new ServerShutdownListenerFactory();
$this->assertIsObject($factory($container));
Expand Down
Loading