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 #67

Merged
merged 4 commits into from
Nov 21, 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.phpcs-cache
/.phpunit.result.cache
/.phpunit.cache
/.psalm-cache/
/clover.xml
/coveralls-upload.json
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"composer/composer": "^2.6.4",
"laminas/laminas-coding-standard": "~2.5.0",
"mikey179/vfsstream": "^1.6.11",
"phpunit/phpunit": "^9.5.26",
"phpunit/phpunit": "^10.4",
"psalm/plugin-phpunit": "^0.18.0",
"vimeo/psalm": "^5.15.0",
"webmozart/assert": "^1.11.0"
Expand Down
587 changes: 234 additions & 353 deletions composer.lock

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
convertDeprecationsToExceptions="true"
colors="true">
cacheDirectory=".phpunit.cache"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
colors="true"
>
<testsuites>
<testsuite name="Laminas\\ComponentInstaller Tests">
<directory>./test</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</source>
</phpunit>
6 changes: 0 additions & 6 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@
<code>__construct</code>
</PossiblyUnusedMethod>
</file>
<file src="test/ComponentInstallerTest.php">
<DeprecatedMethod>
<code>withConsecutive</code>
<code>withConsecutive</code>
</DeprecatedMethod>
</file>
<file src="test/ConfigDiscoveryTest.php">
<InvalidPropertyAssignmentValue>
<code>new Collection([
Expand Down
90 changes: 69 additions & 21 deletions test/ComponentInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@
use Laminas\ComponentInstaller\ComponentInstaller;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\IsAnything;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use ReflectionObject;

use function count;
use function current;
use function dirname;
use function file_get_contents;
use function implode;
use function method_exists;
use function mkdir;
use function next;
use function preg_match;
use function preg_quote;
use function sprintf;
Expand Down Expand Up @@ -191,20 +195,40 @@ private function createOutputAssertions(array $informations): void
$consecutiveArguments = [];

foreach ($informations as $information) {
$consecutiveArguments[] = [
self::callback(static function (string $argument) use ($information): bool {
return preg_match(
sprintf('/%s/', preg_quote($argument, '/')),
$information
) !== false;
}),
];
$consecutiveArguments[] = self::callback(static function (string $argument) use ($information): bool {
return preg_match(
sprintf('/%s/', preg_quote($argument, '/')),
$information
) !== false;
});
}

$consecutive = new class ($consecutiveArguments) extends Constraint {
/**
* @param list<Constraint> $assertions
*/
public function __construct(private array $assertions)
{
$this->assertions[] = new IsAnything();
}

public function matches(mixed $other): bool
{
$assertion = current($this->assertions);
next($this->assertions);
return $assertion->matches($other);
}

public function toString(): string
{
return current($this->assertions)->toString();
}
};

$this->io
->expects(self::exactly(count($consecutiveArguments)))
->method('write')
->withConsecutive(...$consecutiveArguments);
->with($consecutive);
Comment on lines +198 to +231
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to draw attention to this part implementing constraint replacement for removed withConsecutive()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this approach is fine: we're recording stuff, then verifying order at the end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one essentially a custom constraint composing actual constraints and iterating over them on consecutive invocations. If phpunit decides to call constraint multiple times in the future for whatever reason this will break but it is fairly unlikely.

Unlike withConsecutive() this constraint can match only one parameter but here that is exactly what is needed.

I took this approach over willReturnCallback() since I want mock object to record assertion failures as it normally does instead of risking them getting caught by try-catch somewhere in the tested call stack.

}

/**
Expand All @@ -214,22 +238,46 @@ private function createInputAssertions(array $questionsAssertions): void
{
$consecutiveReturnValues = $consecutiveArguments = [];
foreach ($questionsAssertions as $questionAssertion) {
$consecutiveArguments[] = [
self::callback($questionAssertion->assertion()),
];
$consecutiveArguments[] = self::callback($questionAssertion->assertion());
$consecutiveReturnValues[] = $questionAssertion->expectedAnswer;

if ($questionAssertion instanceof RememberedAnswerQuestionAssertion) {
$consecutiveArguments[] = [self::callback($questionAssertion->rememberAnswerAssertion())];
$consecutiveArguments[] = self::callback($questionAssertion->rememberAnswerAssertion());
$consecutiveReturnValues[] = $questionAssertion->remember ? 'y' : 'n';
}
}

$consecutive = new class ($consecutiveArguments) extends Constraint {
/**
* @param list<Constraint> $assertions
*/
public function __construct(private array $assertions)
{
$this->assertions[] = new IsAnything();
}

public function matches(mixed $other): bool
{
$assertion = current($this->assertions);
next($this->assertions);
return $assertion->matches($other);
}

public function toString(): string
{
return current($this->assertions)->toString();
}
};

$matcher = self::exactly(count($consecutiveReturnValues));

$this->io
->expects(self::exactly(count($consecutiveArguments)))
->expects($matcher)
->method('ask')
->withConsecutive(...$consecutiveArguments)
->willReturnOnConsecutiveCalls(...$consecutiveReturnValues);
->with($consecutive)
->willReturnCallback(function () use ($matcher, $consecutiveReturnValues) {
return $consecutiveReturnValues[$matcher->numberOfInvocations() - 1];
});
}

/**
Expand Down Expand Up @@ -332,7 +380,7 @@ public function getModuleDependencies()
* 5: null|string
* }>
*/
public function dependency(): array
public static function dependency(): array
{
return [
// 'description' => [
Expand Down Expand Up @@ -706,7 +754,7 @@ public function getModuleDependencies()
* 2: list<non-empty-string>
* }>
*/
public function modules(): array
public static function modules(): array
{
return [
// 'description' => [
Expand Down Expand Up @@ -1347,7 +1395,7 @@ public function testAppendModuleAndPrependComponent(): void
* 1: array<string, array<array-key, string>>
* }>
*/
public function moduleClass(): array
public static function moduleClass(): array
{
return [
[__DIR__ . '/TestAsset/ModuleBadlyFormatted.php', ['BadlyFormatted\Application' => ['Dependency1']]],
Expand Down Expand Up @@ -1744,7 +1792,7 @@ public function testOnPostPackageInstallDoesNotPromptForIgnoredPackages(): void
* non-empty-string
* }>
*/
public function injectorConfigProvider(): array
public static function injectorConfigProvider(): array
{
$config = <<<'CONFIG'
<?php
Expand Down Expand Up @@ -1932,7 +1980,7 @@ public function testDoesNotModifyRootPackageOnPluginActivation(): void
* 5:list<non-empty-string>
* }>
*/
public function packageUpdateScenarios(): Generator
public static function packageUpdateScenarios(): Generator
{
yield 'package introduces module' => [
[], // Initially installed application modules
Expand Down
2 changes: 1 addition & 1 deletion test/ConfigDiscovery/AbstractConfigAggregatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testLocateReturnsFalseWhenFileDoesNotHaveExpectedContents(): voi
* 0: string
* }>
*/
public function validMezzioConfigContents(): array
public static function validMezzioConfigContents(): array
{
// @codingStandardsIgnoreStart
return [
Expand Down
2 changes: 1 addition & 1 deletion test/ConfigDiscovery/ApplicationConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testLocateReturnsFalseWhenFileDoesNotHaveExpectedContents(): voi
/**
* @psalm-return array<string, array{0: string}>
*/
public function validApplicationConfigContents(): array
public static function validApplicationConfigContents(): array
{
return [
'long-array' => ['<' . "?php\nreturn array(\n 'modules' => array(\n )\n);"],
Expand Down
2 changes: 1 addition & 1 deletion test/ConfigDiscovery/DevelopmentConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testLocateReturnsFalseWhenFileDoesNotHaveExpectedContents(): voi
/**
* @psalm-return array<string, array{0: string}>
*/
public function validDevelopmentConfigContents(): array
public static function validDevelopmentConfigContents(): array
{
return [
'long-array' => ['<' . "?php\nreturn array(\n 'modules' => array(\n )\n);"],
Expand Down
2 changes: 1 addition & 1 deletion test/ConfigDiscovery/MezzioConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testLocateReturnsFalseWhenFileDoesNotHaveExpectedContents(): voi
/**
* @psalm-return array<string, array{0: string}>
*/
public function validMezzioConfigContents(): array
public static function validMezzioConfigContents(): array
{
// @codingStandardsIgnoreStart
return [
Expand Down
2 changes: 1 addition & 1 deletion test/ConfigDiscovery/ModulesConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testLocateReturnsFalseWhenFileDoesNotHaveExpectedContents(): voi
/**
* @psalm-return array<string, array{0: string}>
*/
public function validModulesConfigContents(): array
public static function validModulesConfigContents(): array
{
return [
'long-array' => ['<' . "?php\nreturn array(\n);"],
Expand Down
Loading