This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
forked from samsonasik/expressive-composer-installer
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix/48' into develop
Forward port #48
- Loading branch information
Showing
9 changed files
with
460 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @see https://github.com/zendframework/zend-expressive-skeleton for the canonical source repository | ||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license https://github.com/zendframework/zend-expressive-skeleton/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
namespace ExpressiveInstallerTest; | ||
|
||
use Aura\Di\Container as AuraContainer; | ||
use ExpressiveInstaller\OptionalPackages; | ||
use Interop\Container\ContainerInterface; | ||
use Interop\Container\Pimple\PimpleInterop as PimpleInteropContainer; | ||
use ReflectionProperty; | ||
use Zend\Expressive; | ||
use Zend\ServiceManager\ServiceManager as ZendServiceManagerContainer; | ||
|
||
class ContainersTest extends InstallerTestCase | ||
{ | ||
protected $teardownFiles = [ | ||
'/config/container.php', | ||
'/config/autoload/routes.global.php', | ||
]; | ||
|
||
/** | ||
* @dataProvider containerProvider | ||
*/ | ||
public function testContainer( | ||
$containerOption, | ||
$routerOption, | ||
$copyFilesKey, | ||
$expectedResponseStatusCode, | ||
$expectedContainer | ||
) { | ||
$r = new ReflectionProperty(OptionalPackages::class, 'config'); | ||
$r->setAccessible(true); | ||
$config = $r->getValue(); | ||
|
||
// Install packages | ||
$this->installPackage( | ||
$config['questions']['container']['options'][$containerOption], | ||
$copyFilesKey | ||
); | ||
$this->installPackage( | ||
$config['questions']['router']['options'][$routerOption], | ||
$copyFilesKey | ||
); | ||
|
||
// Test container | ||
$container = $this->getContainer(); | ||
$this->assertInstanceOf(ContainerInterface::class, $container); | ||
$this->assertInstanceOf($expectedContainer, $container); | ||
$this->assertTrue($container->has(Expressive\Helper\UrlHelper::class)); | ||
$this->assertTrue($container->has(Expressive\Helper\ServerUrlHelper::class)); | ||
$this->assertTrue($container->has(Expressive\Application::class)); | ||
$this->assertTrue($container->has(Expressive\Router\RouterInterface::class)); | ||
|
||
// Test home page | ||
$response = $this->getAppResponse(); | ||
$this->assertEquals($expectedResponseStatusCode, $response->getStatusCode()); | ||
} | ||
|
||
public function containerProvider() | ||
{ | ||
// $containerOption, $routerOption, $copyFilesKey, $expectedResponseStatusCode, $expectedContainer | ||
return [ | ||
'aura-minimal' => [1, 2, 'minimal-files', 404, AuraContainer::class], | ||
'aura-full' => [1, 2, 'copy-files', 200, AuraContainer::class], | ||
'pimple-minimal' => [2, 2, 'minimal-files', 404, PimpleInteropContainer::class], | ||
'pimple-full' => [2, 2, 'copy-files', 200, PimpleInteropContainer::class], | ||
'zend-sm-minimal' => [3, 2, 'minimal-files', 404, ZendServiceManagerContainer::class], | ||
'zend-sm-full' => [3, 2, 'copy-files', 200, ZendServiceManagerContainer::class], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @see https://github.com/zendframework/zend-expressive-skeleton for the canonical source repository | ||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license https://github.com/zendframework/zend-expressive-skeleton/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
namespace ExpressiveInstallerTest; | ||
|
||
use Composer\Factory; | ||
use Composer\IO\IOInterface; | ||
use Composer\Json\JsonFile; | ||
use ExpressiveInstaller\OptionalPackages; | ||
use Interop\Container\ContainerInterface; | ||
use Prophecy\Argument; | ||
use Psr\Http\Message\ResponseInterface; | ||
use ReflectionProperty; | ||
use Zend\Diactoros\Response; | ||
use Zend\Diactoros\ServerRequest; | ||
use Zend\Expressive\Application; | ||
|
||
class InstallerTestCase extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var IOInterface | ||
*/ | ||
private $io; | ||
|
||
private $projectRoot; | ||
|
||
/** | ||
* @var ContainerInterface | ||
*/ | ||
protected $container; | ||
|
||
protected $response; | ||
|
||
protected $teardownFiles = []; | ||
|
||
public function setup() | ||
{ | ||
$this->response = null; | ||
|
||
$this->cleanup(); | ||
|
||
$this->io = $this->prophesize('Composer\IO\IOInterface'); | ||
|
||
$composerDefinition = new ReflectionProperty(OptionalPackages::class, 'composerDefinition'); | ||
$composerDefinition->setAccessible(true); | ||
|
||
// Get composer.json | ||
$composerFile = Factory::getComposerFile(); | ||
$json = new JsonFile($composerFile); | ||
$composerDefinition->setValue($json->read()); | ||
|
||
$this->projectRoot = realpath(dirname($composerFile)); | ||
|
||
$config = new ReflectionProperty(OptionalPackages::class, 'config'); | ||
$config->setAccessible(true); | ||
$config->setValue(require 'src/ExpressiveInstaller/config.php'); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
parent::tearDown(); | ||
|
||
$this->cleanup(); | ||
} | ||
|
||
public function installPackage($config, $copyFilesKey) | ||
{ | ||
/* TODO: First we need to set $composerDefinition, $composerRequires, $composerDevRequires and $stabilityFlags; | ||
// Add packages to install | ||
if (isset($config['packages'])) { | ||
foreach ($config['packages'] as $packageName) { | ||
OptionalPackages::addPackage($this->io, $packageName, $this->config['packages'][$packageName]); | ||
} | ||
}*/ | ||
|
||
// Copy files | ||
if (isset($config[$copyFilesKey])) { | ||
foreach ($config[$copyFilesKey] as $source => $target) { | ||
OptionalPackages::copyFile($this->io->reveal(), $this->projectRoot, $source, $target); | ||
} | ||
} | ||
} | ||
|
||
public function cleanup() | ||
{ | ||
foreach ($this->teardownFiles as $file) { | ||
if (is_file($this->projectRoot.$file)) { | ||
unlink($this->projectRoot.$file); | ||
} | ||
} | ||
} | ||
|
||
public function getContainer() | ||
{ | ||
if (!$this->container) { | ||
/** @var ContainerInterface $container */ | ||
$this->container = require 'config/container.php'; | ||
} | ||
|
||
return $this->container; | ||
} | ||
|
||
public function getAppResponse($path = '/') | ||
{ | ||
$container = $this->getContainer(); | ||
|
||
/** @var Application $app */ | ||
$app = $container->get('Zend\Expressive\Application'); | ||
$request = new ServerRequest([], [], 'https://example.com'.$path, 'GET'); | ||
|
||
/** @var ResponseInterface $response */ | ||
$response = $app($request, new Response()); | ||
|
||
return $response; | ||
} | ||
} |
Oops, something went wrong.