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

PHP 8.0 support #38

Merged
merged 8 commits into from
May 10, 2021
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
},
"require": {
"php": "^7.3",
"php": "^7.3 || ~8.0.0",
"composer/package-versions-deprecated": "^1.10.99",
"laminas/laminas-component-installer": "^2.1.2",
"laminas/laminas-config-aggregator": "^1.2",
Expand All @@ -48,8 +48,8 @@
},
"require-dev": {
"composer/composer": "^1.5 || ^2.0 || ^2.0.0-alpha3",
"chubbyphp/chubbyphp-laminas-config": "^1.0",
"elie29/zend-phpdi-config": "^6.0",
"chubbyphp/chubbyphp-laminas-config": "^1.1",
"elie29/zend-phpdi-config": "^6.0 || ^8.0",
"filp/whoops": "^2.7.1",
"jsoumelidis/zend-sf-di-config": "^0.4",
"laminas/laminas-auradi-config": "^2.0.1",
Expand All @@ -70,7 +70,7 @@
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.3.7",
"phpunit/phpunit": "^9.4.1",
"roave/security-advisories": "dev-master"
},
"autoload": {
Expand Down
41 changes: 27 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./src/MezzioInstaller/Resources</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="App\\Tests">
<directory>./test</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
verbose="true"
colors="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">test</directory>
Copy link
Member

Choose a reason for hiding this comment

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

The suffix attribute can be omitted because it is redundant with the value Test.php.

</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix=".php">./src/MezzioInstaller/Resources</directory>
</exclude>
</coverage>
</phpunit>
3 changes: 2 additions & 1 deletion src/App/src/Handler/HomePageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Handler;

use Aura\Di\Container;
use Chubbyphp\Container\MinimalContainer;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Laminas\ServiceManager\ServiceManager;
Expand Down Expand Up @@ -70,7 +71,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$data['containerName'] = 'PHP-DI';
$data['containerDocs'] = 'http://php-di.org';
break;
case \Chubbyphp\Container\Container::class:
case MinimalContainer::class:
$data['containerName'] = 'Chubbyphp Container';
$data['containerDocs'] = 'https://github.com/chubbyphp/chubbyphp-container';
break;
Expand Down
6 changes: 3 additions & 3 deletions test/AppTest/Handler/HomePageHandlerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public function testFactoryWithoutTemplate()
$factory = new HomePageHandlerFactory();
$this->container->has(TemplateRendererInterface::class)->willReturn(false);

$this->assertInstanceOf(HomePageHandlerFactory::class, $factory);
self::assertInstanceOf(HomePageHandlerFactory::class, $factory);

$homePage = $factory($this->container->reveal());

$this->assertInstanceOf(HomePageHandler::class, $homePage);
self::assertInstanceOf(HomePageHandler::class, $homePage);
}

public function testFactoryWithTemplate()
Expand All @@ -51,6 +51,6 @@ public function testFactoryWithTemplate()

$homePage = $factory($this->container->reveal());

$this->assertInstanceOf(HomePageHandler::class, $homePage);
self::assertInstanceOf(HomePageHandler::class, $homePage);
}
}
4 changes: 2 additions & 2 deletions test/AppTest/Handler/HomePageHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testReturnsJsonResponseWhenNoTemplateRendererProvided()
$this->prophesize(ServerRequestInterface::class)->reveal()
);

$this->assertInstanceOf(JsonResponse::class, $response);
self::assertInstanceOf(JsonResponse::class, $response);
}

public function testReturnsHtmlResponseWhenTemplateRendererProvided()
Expand All @@ -65,6 +65,6 @@ public function testReturnsHtmlResponseWhenTemplateRendererProvided()
$this->prophesize(ServerRequestInterface::class)->reveal()
);

$this->assertInstanceOf(HtmlResponse::class, $response);
self::assertInstanceOf(HtmlResponse::class, $response);
}
}
4 changes: 2 additions & 2 deletions test/AppTest/Handler/PingHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testResponse()

$json = json_decode((string) $response->getBody());

$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertTrue(isset($json->ack));
self::assertInstanceOf(JsonResponse::class, $response);
self::assertTrue(isset($json->ack));
}
}
6 changes: 3 additions & 3 deletions test/MezzioInstallerTest/AddPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ public function testAddPackage(string $packageName, string $packageVersion, ?int

$installer->addPackage($packageName, $packageVersion);

$this->assertPackage('laminas/laminas-stdlib', $installer);
self::assertPackage('laminas/laminas-stdlib', $installer);

$r = new ReflectionProperty($installer, 'stabilityFlags');
$r->setAccessible(true);
$stabilityFlags = $r->getValue($installer);

// Stability flags are only set for non-stable packages
if ($expectedStability) {
$this->assertArrayHasKey($packageName, $stabilityFlags);
$this->assertEquals($expectedStability, $stabilityFlags[$packageName]);
self::assertArrayHasKey($packageName, $stabilityFlags);
self::assertEquals($expectedStability, $stabilityFlags[$packageName]);
}
}

Expand Down
26 changes: 13 additions & 13 deletions test/MezzioInstallerTest/ContainersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace MezzioInstallerTest;

use Aura\Di\Container as AuraContainer;
use Chubbyphp\Container\Container as ChubbyphpContainer;
use Chubbyphp\Container\MinimalContainer as ChubbyphpMinimalContainer;
use DI\Container as PhpDIContainer;
use Laminas\ServiceManager\ServiceManager as LaminasManagerContainer;
use Mezzio;
Expand Down Expand Up @@ -65,14 +65,14 @@ public function testContainer(
$config['questions']['container'],
$containerOption
);
$this->assertTrue($containerResult);
self::assertTrue($containerResult);

// Install router
$routerResult = $this->installer->processAnswer(
$config['questions']['router'],
$routerOption
);
$this->assertTrue($routerResult);
self::assertTrue($routerResult);

$configFile = $this->projectRoot . DIRECTORY_SEPARATOR . '/config/config.php';
$configFileContents = file_get_contents($configFile);
Expand All @@ -85,17 +85,17 @@ public function testContainer(

// Test container
$container = $this->getContainer();
$this->assertInstanceOf(ContainerInterface::class, $container);
$this->assertInstanceOf($expectedContainer, $container);
$this->assertTrue($container->has(Mezzio\Helper\UrlHelper::class));
$this->assertTrue($container->has(Mezzio\Helper\ServerUrlHelper::class));
$this->assertTrue($container->has(Mezzio\Application::class));
$this->assertTrue($container->has(Mezzio\Router\RouterInterface::class));
self::assertInstanceOf(ContainerInterface::class, $container);
self::assertInstanceOf($expectedContainer, $container);
self::assertTrue($container->has(Mezzio\Helper\UrlHelper::class));
self::assertTrue($container->has(Mezzio\Helper\ServerUrlHelper::class));
self::assertTrue($container->has(Mezzio\Application::class));
self::assertTrue($container->has(Mezzio\Router\RouterInterface::class));

// Test home page
$setupRoutes = strpos($copyFilesKey, 'minimal') !== 0;
$response = $this->getAppResponse('/', $setupRoutes);
$this->assertEquals($expectedResponseStatusCode, $response->getStatusCode());
self::assertEquals($expectedResponseStatusCode, $response->getStatusCode());
}

public function containerProvider(): array
Expand All @@ -121,9 +121,9 @@ public function containerProvider(): array
'php-di-minimal' => [OptionalPackages::INSTALL_MINIMAL, 6, 2, 'minimal-files', 404, PhpDIContainer::class],
'php-di-flat' => [OptionalPackages::INSTALL_FLAT, 6, 2, 'copy-files', 200, PhpDIContainer::class],
'php-di-modular' => [OptionalPackages::INSTALL_MODULAR, 6, 2, 'copy-files', 200, PhpDIContainer::class],
'chubbyphp-c-minimal' => [OptionalPackages::INSTALL_MINIMAL, 7, 2, 'minimal-files', 404, ChubbyphpContainer::class],
'chubbyphp-c-flat' => [OptionalPackages::INSTALL_FLAT, 7, 2, 'copy-files', 200, ChubbyphpContainer::class],
'chubbyphp-c-modular' => [OptionalPackages::INSTALL_MODULAR, 7, 2, 'copy-files', 200, ChubbyphpContainer::class],
'chubbyphp-c-minimal' => [OptionalPackages::INSTALL_MINIMAL, 7, 2, 'minimal-files', 404, ChubbyphpMinimalContainer::class],
'chubbyphp-c-flat' => [OptionalPackages::INSTALL_FLAT, 7, 2, 'copy-files', 200, ChubbyphpMinimalContainer::class],
'chubbyphp-c-modular' => [OptionalPackages::INSTALL_MODULAR, 7, 2, 'copy-files', 200, ChubbyphpMinimalContainer::class],
];
// @codingStandardsIgnoreEnd
}
Expand Down
16 changes: 8 additions & 8 deletions test/MezzioInstallerTest/CopyResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ protected function setUp(): void

public function testTargetFileDoesNotExist()
{
$this->assertFalse($this->project->hasChild('data'));
$this->assertFalse($this->project->hasChild('data/target.php'));
self::assertFalse($this->project->hasChild('data'));
self::assertFalse($this->project->hasChild('data/target.php'));
}

public function testResourceIsCopiedIfItDoesNotExist()
Expand All @@ -36,9 +36,9 @@ public function testResourceIsCopiedIfItDoesNotExist()

$installer->copyResource('config.php', 'data/target.php');

$this->assertTrue($this->project->hasChild('data'));
$this->assertTrue($this->project->hasChild('data/target.php'));
$this->assertFileEquals(
self::assertTrue($this->project->hasChild('data'));
self::assertTrue($this->project->hasChild('data/target.php'));
self::assertFileEquals(
$this->packageRoot . '/src/MezzioInstaller/config.php',
vfsStream::url('project-root/data/target.php')
);
Expand All @@ -51,14 +51,14 @@ public function testResourceIsNotCopiedIfItExists()
->at($this->project)
->setContent('TEST');

$this->assertTrue($this->project->hasChild('data/target.php'));
self::assertTrue($this->project->hasChild('data/target.php'));

// Copy file (should not copy file)
$installer = $this->createOptionalPackages($this->projectRoot);
$installer->copyResource('config.php', 'data/target.php');

$this->assertTrue($this->project->hasChild('data/target.php'));
$this->assertEquals(
self::assertTrue($this->project->hasChild('data/target.php'));
self::assertEquals(
'TEST',
file_get_contents(vfsStream::url('project-root/data/target.php'))
);
Expand Down
20 changes: 10 additions & 10 deletions test/MezzioInstallerTest/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ public function testErrorHandlerIsNotInstalled()
$config['questions']['container'],
3
);
$this->assertTrue($containerResult);
self::assertTrue($containerResult);

// Enable development mode
$this->enableDevelopmentMode();

// Test container
$container = $this->getContainer();
$this->assertTrue($container->has(ErrorResponseGenerator::class));
$this->assertFalse($container->has('Mezzio\Whoops'));
$this->assertFalse($container->has('Mezzio\WhoopsPageHandler'));
self::assertTrue($container->has(ErrorResponseGenerator::class));
self::assertFalse($container->has('Mezzio\Whoops'));
self::assertFalse($container->has('Mezzio\WhoopsPageHandler'));
}

/**
Expand All @@ -75,26 +75,26 @@ public function testErrorHandler(
$config['questions']['container'],
$containerOption
);
$this->assertTrue($containerResult);
self::assertTrue($containerResult);

// Install error handler
$containerResult = $this->installer->processAnswer(
$config['questions']['error-handler'],
$errorHandlerOption
);
$this->assertTrue($containerResult);
self::assertTrue($containerResult);

// Enable development mode
$this->enableDevelopmentMode();

// Test container
$container = $this->getContainer();
$this->assertTrue($container->has(ErrorResponseGenerator::class));
$this->assertTrue($container->has('Mezzio\Whoops'));
$this->assertTrue($container->has('Mezzio\WhoopsPageHandler'));
self::assertTrue($container->has(ErrorResponseGenerator::class));
self::assertTrue($container->has('Mezzio\Whoops'));
self::assertTrue($container->has('Mezzio\WhoopsPageHandler'));

$config = $container->get('config');
$this->assertEquals(
self::assertEquals(
$expectedErrorHandler,
$config['dependencies']['factories'][ErrorResponseGenerator::class]
);
Expand Down