From 4a47bba42905665d1682d7f8af3ecce58df60952 Mon Sep 17 00:00:00 2001 From: maks Date: Tue, 5 Feb 2019 20:39:03 +0100 Subject: [PATCH 1/5] Add case for 'Pimple\Psr11\Container' in HP --- src/App/src/Handler/HomePageHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/App/src/Handler/HomePageHandler.php b/src/App/src/Handler/HomePageHandler.php index 980adc5..5bf6cf4 100644 --- a/src/App/src/Handler/HomePageHandler.php +++ b/src/App/src/Handler/HomePageHandler.php @@ -53,6 +53,7 @@ public function handle(ServerRequestInterface $request) : ResponseInterface $data['containerDocs'] = 'http://auraphp.com/packages/2.x/Di.html'; break; case 'Pimple\Container': + case 'Pimple\Psr11\Container': $data['containerName'] = 'Pimple'; $data['containerDocs'] = 'https://pimple.symfony.com/'; break; From 1f29ac84fc7e6faf6487bacab113f712054eedf4 Mon Sep 17 00:00:00 2001 From: pine3ree Date: Sun, 10 Feb 2019 02:35:05 +0100 Subject: [PATCH 2/5] Add case for 'Northwoods\Container\InjectorContainer' in HP --- src/App/src/Handler/HomePageHandler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/App/src/Handler/HomePageHandler.php b/src/App/src/Handler/HomePageHandler.php index 5bf6cf4..55c5de4 100644 --- a/src/App/src/Handler/HomePageHandler.php +++ b/src/App/src/Handler/HomePageHandler.php @@ -62,6 +62,7 @@ public function handle(ServerRequestInterface $request) : ResponseInterface $data['containerDocs'] = 'https://docs.zendframework.com/zend-servicemanager/'; break; case 'Auryn\Injector': + case 'Northwoods\Container\InjectorContainer': $data['containerName'] = 'Auryn'; $data['containerDocs'] = 'https://github.com/rdlowrey/Auryn'; break; From 5b6021983839e3eaab771e2a45ecc8b5b796ed6f Mon Sep 17 00:00:00 2001 From: pine3ree Date: Sun, 10 Feb 2019 02:55:16 +0100 Subject: [PATCH 3/5] Add test case for HomePage response content --- .../HomePageResponseTest.php | 218 ++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 test/ExpressiveInstallerTest/HomePageResponseTest.php diff --git a/test/ExpressiveInstallerTest/HomePageResponseTest.php b/test/ExpressiveInstallerTest/HomePageResponseTest.php new file mode 100644 index 0000000..ecfafe4 --- /dev/null +++ b/test/ExpressiveInstallerTest/HomePageResponseTest.php @@ -0,0 +1,218 @@ + PlatesRendererConfigProvider::class, + TwigRenderer::class => TwigRendererConfigProvider::class, + ZendViewRenderer::class => ZendViewRendererConfigProvider::class, + ]; + + // $intallType, $intallType + private $intallTypes = [ + OptionalPackages::INSTALL_FLAT => OptionalPackages::INSTALL_FLAT, + OptionalPackages::INSTALL_MODULAR => OptionalPackages::INSTALL_MODULAR, + ]; + + // $rendererOption, $rendererClass + private $rendererTypes = [ + 'plates' => [1, PlatesRenderer::class], + 'twig' => [2, TwigRenderer::class], + 'zend-view' => [3, ZendViewRenderer::class], + ]; + + // $containerOption, $containerClass + private $containerTypes = [ + 'aura' => [1, AuraContainer::class], + 'pimple' => [2, PimpleContainer::class], + 'zend-sm' => [3, ZendServiceManagerContainer::class], + 'auryn' => [4, AurynContainer::class], + 'sf-di' => [5, SfContainerBuilder::class], + 'php-di' => [6, PhpDIContainer::class], + ]; + + private $expectedContainerAttributes = [ + AuraContainer::class => [ + 'containerName' => 'Aura.Di', + 'containerDocs' => 'http://auraphp.com/packages/2.x/Di.html', + ], + PimpleContainer::class => [ + 'containerName' => 'Pimple', + 'containerDocs' => 'https://pimple.symfony.com/', + ], + ZendServiceManagerContainer::class => [ + 'containerName' => 'Zend Servicemanager', + 'containerDocs' => 'https://docs.zendframework.com/zend-servicemanager/', + ], + AurynContainer::class => [ + 'containerName' => 'Auryn', + 'containerDocs' => 'https://github.com/rdlowrey/Auryn', + ], + SfContainerBuilder::class => [ + 'containerName' => 'Symfony DI Container', + 'containerDocs' => 'https://symfony.com/doc/current/service_container.html', + ], + PhpDIContainer::class => [ + 'containerName' => 'PHP-DI', + 'containerDocs' => 'http://php-di.org', + ], + ]; + + protected function setUp() + { + parent::setUp(); + $this->projectRoot = $this->copyProjectFilesToTempFilesystem(); + $this->installer = $this->createOptionalPackages($this->projectRoot); + } + + protected function tearDown() + { + parent::tearDown(); + chdir($this->packageRoot); + $this->recursiveDelete($this->projectRoot); + $this->tearDownAlternateAutoloader(); + } + + /** + * @runInSeparateProcess + * + * @dataProvider installCasesProvider + */ + public function testHomePageResponseContainsCorrectCountainerInfo( + string $installType, + int $containerOption, + string $containerClass, + int $rendererOption, + string $rendererClass, + string $containerName, + string $containerDocs + ) { + $this->prepareSandboxForInstallType($installType, $this->installer); + + // Install container + $config = $this->getInstallerConfig($this->installer); + $containerResult = $this->installer->processAnswer( + $config['questions']['container'], + $containerOption + ); + $this->assertTrue($containerResult); + + // Install router + $routerResult = $this->installer->processAnswer( + $config['questions']['router'], + $routerOption = 2 // FastRoute, use assignment for clarity + ); + $this->assertTrue($routerResult); + $this->injectRouterConfigProvider(); + + // Install template engine + $templateEngineResult = $this->installer->processAnswer( + $config['questions']['template-engine'], + $rendererOption + ); + $this->assertTrue($templateEngineResult); + $this->injectRendererConfigProvider($rendererClass); + + // Test home page response + $response = $this->getAppResponse('/', true); + $this->assertEquals(200, $response->getStatusCode()); + + // Test response content + $html = (string) $response->getBody()->getContents(); + + $this->assertStringContainsString("Get started with {$containerName}", $html); + $this->assertStringContainsString("href=\"{$containerDocs}\"", $html); + } + + public function installCasesProvider() : Generator + { + // Execute a test case for each container, renderer and non minimal install type + foreach ($this->containerTypes as $containerID => $containerType) { + $containerOption = $containerType[0]; + $containerClass = $containerType[1]; + + $containerName = $this->expectedContainerAttributes[$containerClass]['containerName']; + $containerDocs = $this->expectedContainerAttributes[$containerClass]['containerDocs']; + + foreach ($this->rendererTypes as $rendererID => $rendererType) { + $rendererOption = $rendererType[0]; + $rendererClass = $rendererType[1]; + + foreach ($this->intallTypes as $intallType) { + $name = implode('-', [$containerID, $rendererID, $intallType]); + $args = [ + $intallType, + $containerOption, + $containerClass, + $rendererOption, + $rendererClass, + $containerName, + $containerDocs, + ]; + + yield $name => $args; + } + } + } + } + + public function injectRouterConfigProvider() + { + $configFile = $this->projectRoot . '/config/config.php'; + $contents = file_get_contents($configFile); + $contents = preg_replace( + '/(new ConfigAggregator\(\[)/s', + '$1' . "\n " . FastRouteRouterConfigProvider::class . "::class,\n", + $contents + ); + file_put_contents($configFile, $contents); + } + + public function injectRendererConfigProvider(string $rendererClass) + { + $configFile = $this->projectRoot . '/config/config.php'; + $contents = file_get_contents($configFile); + $contents = preg_replace( + '/(new ConfigAggregator\(\[)/s', + '$1' . "\n " . $this->rendererConfigProviders[$rendererClass] . "::class,\n", + $contents + ); + file_put_contents($configFile, $contents); + } +} From 439d4e32e00294a0eed239c03dfcf2e99d81dc32 Mon Sep 17 00:00:00 2001 From: pine3ree Date: Sun, 10 Feb 2019 03:05:03 +0100 Subject: [PATCH 4/5] update test case assertions: replace assertStringContainsString with simpler assertNotFalse --- test/ExpressiveInstallerTest/HomePageResponseTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ExpressiveInstallerTest/HomePageResponseTest.php b/test/ExpressiveInstallerTest/HomePageResponseTest.php index ecfafe4..926b73b 100644 --- a/test/ExpressiveInstallerTest/HomePageResponseTest.php +++ b/test/ExpressiveInstallerTest/HomePageResponseTest.php @@ -156,8 +156,8 @@ public function testHomePageResponseContainsCorrectCountainerInfo( // Test response content $html = (string) $response->getBody()->getContents(); - $this->assertStringContainsString("Get started with {$containerName}", $html); - $this->assertStringContainsString("href=\"{$containerDocs}\"", $html); + $this->assertNotFalse(strpos($html, "Get started with {$containerName}")); + $this->assertNotFalse(strpos($html, "href=\"{$containerDocs}\"")); } public function installCasesProvider() : Generator From 5d891404190da5213d072b9ff82dc2f4deea8659 Mon Sep 17 00:00:00 2001 From: pine3ree Date: Sun, 10 Feb 2019 04:14:14 +0100 Subject: [PATCH 5/5] update test case: skip zend-view / non zend-sm combinations --- test/ExpressiveInstallerTest/HomePageResponseTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/ExpressiveInstallerTest/HomePageResponseTest.php b/test/ExpressiveInstallerTest/HomePageResponseTest.php index 926b73b..88e0c9d 100644 --- a/test/ExpressiveInstallerTest/HomePageResponseTest.php +++ b/test/ExpressiveInstallerTest/HomePageResponseTest.php @@ -114,7 +114,7 @@ protected function tearDown() * * @dataProvider installCasesProvider */ - public function testHomePageResponseContainsCorrectCountainerInfo( + public function testHomePageResponseContainsCorrectContainerInfo( string $installType, int $containerOption, string $containerClass, @@ -174,6 +174,11 @@ public function installCasesProvider() : Generator $rendererOption = $rendererType[0]; $rendererClass = $rendererType[1]; + // skip zend-view / non zend-sm combinations + if (3 === $rendererOption && 3 !== $containerOption) { + continue; + } + foreach ($this->intallTypes as $intallType) { $name = implode('-', [$containerID, $rendererID, $intallType]); $args = [