Skip to content

Commit

Permalink
Changes to test suite for PHPUnit 10 compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: George Steel <george@net-glue.co.uk>
  • Loading branch information
gsteel authored and Xerkus committed Jan 9, 2024
1 parent d64b574 commit 89e428e
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 61 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@
"require-dev": {
"chubbyphp/chubbyphp-laminas-config": "^1.3.0",
"composer/composer": "^2.6.6",
"elie29/zend-phpdi-config": "^9.0",
"elie29/zend-phpdi-config": "^9.0.1",
"filp/whoops": "^2.15.4",
"jsoumelidis/zend-sf-di-config": "^0.5.1",
"laminas/laminas-coding-standard": "~2.5.0",
"laminas/laminas-development-mode": "^3.10.0",
"laminas/laminas-servicemanager": "^3.22.0",
"laminas/laminas-development-mode": "^3.12.0",
"laminas/laminas-servicemanager": "^3.22.1",
"mezzio/mezzio-fastroute": "^3.11.0",
"mezzio/mezzio-laminasrouter": "^3.9.0",
"mezzio/mezzio-laminasviewrenderer": "^2.15.0",
"mezzio/mezzio-platesrenderer": "^2.10.0",
"mezzio/mezzio-tooling": "^2.8",
"mezzio/mezzio-tooling": "^2.9",
"mezzio/mezzio-twigrenderer": "^2.15.0",
"mikey179/vfsstream": "^1.6.11",
"phpunit/phpunit": "^10.5",
"phpunit/phpunit": "^10.5.5",
"psalm/plugin-phpunit": "^0.18.4",
"roave/security-advisories": "dev-master",
"vimeo/psalm": "^5.18"
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@
<MixedArgument>
<code>$stabilityFlags</code>
</MixedArgument>
<MixedArrayAccess>
<code>$stabilityFlags[$packageName]</code>
</MixedArrayAccess>
<MixedAssignment>
<code>$stabilityFlags</code>
</MixedAssignment>
Expand Down Expand Up @@ -185,11 +182,11 @@
* }>]]></code>
</MoreSpecificReturnType>
<PossiblyInvalidArrayOffset>
<code><![CDATA[$this->expectedContainerAttributes[$containerClass]]]></code>
<code><![CDATA[$this->expectedContainerAttributes[$containerClass]]]></code>
<code><![CDATA[$this->expectedRouterAttributes[$routerClass]]]></code>
<code><![CDATA[$this->rendererConfigProviders[$rendererClass]]]></code>
<code><![CDATA[$this->routerConfigProviders[$routerClass]]]></code>
<code>self::$expectedContainerAttributes[$containerClass]</code>
<code>self::$expectedContainerAttributes[$containerClass]</code>
<code>self::$expectedRouterAttributes[$routerClass]</code>
<code>self::$rendererConfigProviders[$rendererClass]</code>
<code>self::$routerConfigProviders[$routerClass]</code>
</PossiblyInvalidArrayOffset>
</file>
<file src="test/MezzioInstallerTest/OptionalPackagesTestCase.php">
Expand Down
2 changes: 1 addition & 1 deletion test/MezzioInstallerTest/AddPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testAddPackage(string $packageName, string $packageVersion, ?int
}
}

public function packageProvider(): array
public static function packageProvider(): array
{
// $packageName, $packageVersion, $expectedStability
return [
Expand Down
2 changes: 1 addition & 1 deletion test/MezzioInstallerTest/ContainersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function testContainer(
* 5: class-string<ContainerInterface>
* }>
*/
public function containerProvider(): array
public static function containerProvider(): array
{
// phpcs:disable Generic.Files.LineLength.TooLong
// $installType, $containerOption, $routerOption, $copyFilesKey, $expectedResponseStatusCode, $expectedContainer
Expand Down
2 changes: 1 addition & 1 deletion test/MezzioInstallerTest/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testErrorHandler(
);
}

public function errorHandlerProvider(): array
public static function errorHandlerProvider(): array
{
// $installType, $containerOption, $errorHandlerOption, $expectedErrorHandler
return [
Expand Down
48 changes: 24 additions & 24 deletions test/MezzioInstallerTest/HomePageResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,42 @@ class HomePageResponseTest extends OptionalPackagesTestCase
private OptionalPackages $installer;

/** @var array<class-string<RouterInterface>, class-string> */
private array $routerConfigProviders = [
private static array $routerConfigProviders = [
FastRouteRouter::class => FastRouteRouterConfigProvider::class,
LaminasRouter::class => LaminasRouterConfigProvider::class,
];

/** @var array<class-string<TemplateRendererInterface>, class-string> */
private array $rendererConfigProviders = [
private static array $rendererConfigProviders = [
PlatesRenderer::class => PlatesRendererConfigProvider::class,
TwigRenderer::class => TwigRendererConfigProvider::class,
LaminasViewRenderer::class => LaminasViewRendererConfigProvider::class,
];

// $installType, $installType
/** @var array<string, string> */
private array $installTypes = [
private static array $installTypes = [
OptionalPackages::INSTALL_FLAT => OptionalPackages::INSTALL_FLAT,
OptionalPackages::INSTALL_MODULAR => OptionalPackages::INSTALL_MODULAR,
];

// $rendererOption, $rendererClass
/** @var array<string, array<int|class-string<TemplateRendererInterface>>> */
private array $rendererTypes = [
private static array $rendererTypes = [
'plates' => [1, PlatesRenderer::class],
'twig' => [2, TwigRenderer::class],
'laminas-view' => [3, LaminasViewRenderer::class],
];

// $routerOption, $routerClass
/** @var array<string, array<int|class-string<RouterInterface>>> */
private array $routerTypes = [
private static array $routerTypes = [
'fastroute' => [1, FastRouteRouter::class],
'laminas-router' => [2, LaminasRouter::class],
];

/** @var array<class-string<RouterInterface>, array<string, string>> */
private array $expectedRouterAttributes = [
private static array $expectedRouterAttributes = [
FastRouteRouter::class => [
'routerName' => 'FastRoute',
'routerDocs' => 'https://github.com/nikic/FastRoute',
Expand All @@ -89,15 +89,15 @@ class HomePageResponseTest extends OptionalPackagesTestCase

// $containerOption, $containerClass
/** @var array<string, array<int|class-string<ContainerInterface>>> */
private array $containerTypes = [
private static array $containerTypes = [
'laminas-servicemanager' => [1, LaminasServiceManagerContainer::class],
'sf-di' => [2, SfContainerBuilder::class],
'php-di' => [3, PhpDIContainer::class],
'chubbyphp-container' => [4, ChubbyphpContainer::class],
];

/** @var array<class-string<ContainerInterface>, array<string, string>> */
private array $expectedContainerAttributes = [
private static array $expectedContainerAttributes = [
LaminasServiceManagerContainer::class => [
'containerName' => 'Laminas Servicemanager',
'containerDocs' => 'https://docs.laminas.dev/laminas-servicemanager/',
Expand Down Expand Up @@ -190,17 +190,17 @@ public function testHomePageHtmlResponseContainsExpectedInfo(
* 5: string
* }>
*/
public function installCasesProvider(): Generator
public static function installCasesProvider(): Generator
{
// Execute a test case for each container, renderer and non minimal install type
foreach ($this->containerTypes as $containerId => $containerType) {
foreach (self::$containerTypes as $containerId => $containerType) {
$containerOption = $containerType[0];
$containerClass = $containerType[1];

$containerName = $this->expectedContainerAttributes[$containerClass]['containerName'];
$containerDocs = $this->expectedContainerAttributes[$containerClass]['containerDocs'];
$containerName = self::$expectedContainerAttributes[$containerClass]['containerName'];
$containerDocs = self::$expectedContainerAttributes[$containerClass]['containerDocs'];

foreach ($this->rendererTypes as $rendererId => $rendererType) {
foreach (self::$rendererTypes as $rendererId => $rendererType) {
$rendererOption = $rendererType[0];
$rendererClass = $rendererType[1];

Expand All @@ -209,7 +209,7 @@ public function installCasesProvider(): Generator
continue;
}

foreach ($this->installTypes as $installType) {
foreach (self::$installTypes as $installType) {
$name = implode('--', [$containerId, $rendererId, $installType]);
$args = [
$installType,
Expand Down Expand Up @@ -289,23 +289,23 @@ public function testHomePageJsonResponseContainsExpectedInfo(
* 7: string
* }>
*/
public function rendererlessInstallCasesProvider(): Generator
public static function rendererlessInstallCasesProvider(): Generator
{
// Execute a test case for each install type and container, without any renderer
foreach ($this->containerTypes as $containerId => $containerType) {
foreach (self::$containerTypes as $containerId => $containerType) {
$containerOption = $containerType[0];
$containerClass = $containerType[1];

$containerName = $this->expectedContainerAttributes[$containerClass]['containerName'];
$containerDocs = $this->expectedContainerAttributes[$containerClass]['containerDocs'];
$containerName = self::$expectedContainerAttributes[$containerClass]['containerName'];
$containerDocs = self::$expectedContainerAttributes[$containerClass]['containerDocs'];

foreach ($this->routerTypes as $routerId => $routerType) {
foreach (self::$routerTypes as $routerId => $routerType) {
$routerOption = $routerType[0];
$routerClass = $routerType[1];
$routerName = $this->expectedRouterAttributes[$routerClass]['routerName'];
$routerDocs = $this->expectedRouterAttributes[$routerClass]['routerDocs'];
$routerName = self::$expectedRouterAttributes[$routerClass]['routerName'];
$routerDocs = self::$expectedRouterAttributes[$routerClass]['routerDocs'];

foreach ($this->installTypes as $installType) {
foreach (self::$installTypes as $installType) {
$name = implode('--', [$containerId, $routerId, $installType]);
$args = [
$installType,
Expand All @@ -330,7 +330,7 @@ public function injectRouterConfigProvider(string $routerClass): void
$contents = file_get_contents($configFile);
$contents = preg_replace(
'#(new ConfigAggregator\(\[)#s',
'$1' . "\n " . $this->routerConfigProviders[$routerClass] . "::class,\n",
'$1' . "\n " . self::$routerConfigProviders[$routerClass] . "::class,\n",
$contents
);
file_put_contents($configFile, $contents);
Expand All @@ -342,7 +342,7 @@ public function injectRendererConfigProvider(string $rendererClass): void
$contents = file_get_contents($configFile);
$contents = preg_replace(
'#(new ConfigAggregator\(\[)#s',
'$1' . "\n " . $this->rendererConfigProviders[$rendererClass] . "::class,\n",
'$1' . "\n " . self::$rendererConfigProviders[$rendererClass] . "::class,\n",
$contents
);
file_put_contents($configFile, $contents);
Expand Down
14 changes: 4 additions & 10 deletions test/MezzioInstallerTest/OptionalPackagesTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,17 @@ protected function createOptionalPackages(?string $projectRoot = null): Optional
);
}

/**
* @return Composer&MockObject
*/
protected function createComposer()
protected function createComposer(): Composer&MockObject
{
$this->composer = $this->createMock(Composer::class);
$this->composer->method('getPackage')->will(
$this->returnCallback(fn (): MockObject => $this->createRootPackage())
$this->composer->method('getPackage')->willReturn(
$this->createRootPackage(),
);

return $this->composer;
}

/**
* @return RootPackage&MockObject
*/
protected function createRootPackage()
protected function createRootPackage(): RootPackage&MockObject
{
$composerJson = json_decode(
file_get_contents($this->packageRoot . '/composer.json'),
Expand Down
2 changes: 1 addition & 1 deletion test/MezzioInstallerTest/PromptForOptionalPackagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function tearDown(): void
* 3: OptionalPackageSpec
* }>
*/
public function promptCombinations(): Generator
public static function promptCombinations(): Generator
{
$config = require __DIR__ . '/../../src/MezzioInstaller/config.php';
/** @psalm-var array<string, QuestionSpec> $questions */
Expand Down
6 changes: 3 additions & 3 deletions test/MezzioInstallerTest/RequestInstallTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function setUp(): void
$this->installer = $this->createOptionalPackages();
}

public function installSelections(): array
public static function installSelections(): array
{
return [
OptionalPackages::INSTALL_MINIMAL => ['1', OptionalPackages::INSTALL_MINIMAL],
Expand All @@ -35,9 +35,9 @@ public function installSelections(): array
public function testRequestInstallTypeReturnsExpectedConstantValue(string $selection, string $expected): void
{
$this->io
->expects($this->once())
->expects(self::once())
->method('ask')
->with($this->callback(fn ($value): bool => $this->assertQueryPrompt($value)), '2')
->with(self::callback(fn ($value): bool => self::assertQueryPrompt($value)), '2')
->willReturn($selection);

self::assertSame($expected, $this->installer->requestInstallType());
Expand Down
12 changes: 6 additions & 6 deletions test/MezzioInstallerTest/RoutersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RoutersTest extends OptionalPackagesTestCase
use ProjectSandboxTrait;

/** @var array<array-key,array<string,string|array<array-key,string>>> */
private array $expectedRoutes = [
private static array $expectedRoutes = [
[
'name' => 'home',
'path' => '/',
Expand Down Expand Up @@ -131,17 +131,17 @@ public function testRouter(
}
}

public function routerProvider(): array
public static function routerProvider(): array
{
// @codingStandardsIgnoreStart
// $installType, $containerOption, $routerOption, $copyFilesKey, $dependencyKey, $expectedResponseStatusCode, $expectedRoutes, $expectedRouter
return [
'fastroute-minimal' => [OptionalPackages::INSTALL_MINIMAL, 2, 1, 'minimal-files', 'aliases', 404, [], FastRouteRouter::class],
'fastroute-flat' => [OptionalPackages::INSTALL_FLAT, 2, 1, 'copy-files', 'aliases', 200, $this->expectedRoutes, FastRouteRouter::class],
'fastroute-modular' => [OptionalPackages::INSTALL_MODULAR, 2, 1, 'copy-files', 'aliases', 200, $this->expectedRoutes, FastRouteRouter::class],
'fastroute-flat' => [OptionalPackages::INSTALL_FLAT, 2, 1, 'copy-files', 'aliases', 200, self::$expectedRoutes, FastRouteRouter::class],
'fastroute-modular' => [OptionalPackages::INSTALL_MODULAR, 2, 1, 'copy-files', 'aliases', 200, self::$expectedRoutes, FastRouteRouter::class],
'laminas-router-minimal' => [OptionalPackages::INSTALL_MINIMAL, 2, 2, 'minimal-files', 'aliases', 404, [], LaminasRouter::class],
'laminas-router-flat' => [OptionalPackages::INSTALL_FLAT, 2, 2, 'copy-files', 'aliases', 200, $this->expectedRoutes, LaminasRouter::class],
'laminas-router-modular' => [OptionalPackages::INSTALL_MODULAR, 2, 2, 'copy-files', 'aliases', 200, $this->expectedRoutes, LaminasRouter::class],
'laminas-router-flat' => [OptionalPackages::INSTALL_FLAT, 2, 2, 'copy-files', 'aliases', 200, self::$expectedRoutes, LaminasRouter::class],
'laminas-router-modular' => [OptionalPackages::INSTALL_MODULAR, 2, 2, 'copy-files', 'aliases', 200, self::$expectedRoutes, LaminasRouter::class],
];
// @codingStandardsIgnoreEnd
}
Expand Down

0 comments on commit 89e428e

Please sign in to comment.