From 9de27e1278e356b87b0d42370ada21a905b001c1 Mon Sep 17 00:00:00 2001 From: Sergio Brighenti Date: Sat, 26 Sep 2020 20:53:07 +0200 Subject: [PATCH] Create config for the test suite --- bootstrap/app.php | 6 +++--- index.php | 1 + phpunit.xml | 4 ++++ tests/Client.php | 4 ---- tests/TestCase.php | 5 +---- tests/bootstrap.php | 4 ++++ tests/config_test.php | 17 +++++++++++++++++ 7 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 tests/config_test.php diff --git a/bootstrap/app.php b/bootstrap/app.php index df305f9..4f248d3 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -16,11 +16,11 @@ use Psr\Container\ContainerInterface as Container; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\RequestHandlerInterface as RequestHandler; -if (!file_exists(BASE_DIR.'config.php') && is_dir(BASE_DIR.'install/')) { +if (!file_exists(CONFIG_FILE) && is_dir(BASE_DIR.'install/')) { header('Location: ./install/'); exit(); } else { - if (!file_exists(BASE_DIR.'config.php') && !is_dir(BASE_DIR.'install/')) { + if (!file_exists(CONFIG_FILE) && !is_dir(BASE_DIR.'install/')) { exit('Cannot find the config file.'); } } @@ -48,7 +48,7 @@ $config = array_replace_recursive([ 'base_domain' => null, 'user_domain' => null, ], -], require BASE_DIR.'config.php'); +], require CONFIG_FILE); $builder = new ContainerBuilder(); diff --git a/index.php b/index.php index 6427241..e721025 100644 --- a/index.php +++ b/index.php @@ -5,6 +5,7 @@ require __DIR__.'/vendor/autoload.php'; define('BASE_DIR', realpath(__DIR__).DIRECTORY_SEPARATOR); define('PLATFORM_VERSION', json_decode(file_get_contents('composer.json'))->version); +define('CONFIG_FILE', BASE_DIR.'config.php'); $app = require_once __DIR__.'/bootstrap/app.php'; $app->run(); diff --git a/phpunit.xml b/phpunit.xml index 07d9b51..883b726 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -26,4 +26,8 @@ lowUpperBound="70" highLowerBound="90"/> + + + + diff --git a/tests/Client.php b/tests/Client.php index 600a6ad..8115591 100644 --- a/tests/Client.php +++ b/tests/Client.php @@ -11,14 +11,10 @@ class Client extends AbstractBrowser { protected function doRequest($request) { - define('BASE_DIR', realpath(__DIR__.'/../').DIRECTORY_SEPARATOR); - define('PLATFORM_VERSION', json_decode(file_get_contents(BASE_DIR.'composer.json'))->version); - /** @var \Slim\App $app */ $app = require_once BASE_DIR.'bootstrap/app.php'; $response = $app->handle(new ServerRequest($request->getMethod(), $request->getUri(), [], $request->getContent())); - return new Response($response->getBody()->getContents(), $response->getStatusCode(), $response->getHeaders()); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 002928c..c804a63 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,8 +2,8 @@ namespace Tests; -use GuzzleHttp\Psr7\Response; use PHPUnit\Framework\TestCase as BaseTestCase; +use Symfony\Component\BrowserKit\Response; abstract class TestCase extends BaseTestCase { @@ -12,9 +12,6 @@ abstract class TestCase extends BaseTestCase protected function setUp() { - $_SERVER['HTTP_HOST'] = 'http://localhost'; - $_SERVER['HTTPS'] = false; - $this->client = new Client(); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3fca1db..5edef49 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,3 +1,7 @@ version); +define('CONFIG_FILE', BASE_DIR.'tests/config_test.php'); + ob_start(); diff --git a/tests/config_test.php b/tests/config_test.php new file mode 100644 index 0000000..7687116 --- /dev/null +++ b/tests/config_test.php @@ -0,0 +1,17 @@ + true, +// 'db' => +// [ +// 'connection' => 'sqlite', +// 'dsn' => ':memory:', +// 'username' => null, +// 'password' => null, +// ], + 'storage' => + [ + 'driver' => 'local', + 'path' => 'storage/test', + ], +]; \ No newline at end of file