From 87ba7a7179deaa46d9d2a36a1aaf116b9ebf8ef0 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 26 Jan 2019 09:09:49 +0100 Subject: [PATCH] Updated structure for tests config files --- build.sh | 2 +- config/config.php | 4 ++++ .../test/bootstrap_db_tests.php | 6 +++--- config/test/swoole.global.php | 12 ++++++++++++ module/Common/test-db/ApiTest/ApiTestCase.php | 10 ++++++++++ .../test-db/{DbUnit => DbTest}/DatabaseTestCase.php | 4 +--- .../test-db/Repository/ShortUrlRepositoryTest.php | 2 +- module/Core/test-db/Repository/TagRepositoryTest.php | 2 +- .../Core/test-db/Repository/VisitRepositoryTest.php | 2 +- phpunit-db.xml | 9 +++++---- 10 files changed, 39 insertions(+), 14 deletions(-) rename db_tests_bootstrap.php => config/test/bootstrap_db_tests.php (76%) create mode 100644 config/test/swoole.global.php create mode 100644 module/Common/test-db/ApiTest/ApiTestCase.php rename module/Common/test-db/{DbUnit => DbTest}/DatabaseTestCase.php (82%) diff --git a/build.sh b/build.sh index cab2f4d3..dd287783 100755 --- a/build.sh +++ b/build.sh @@ -28,11 +28,11 @@ rsync -av * "${builtcontent}" \ --exclude=docs \ --exclude=indocker \ --exclude=docker* \ - --exclude=func_tests_bootstrap.php \ --exclude=php* \ --exclude=infection.json \ --exclude=phpstan.neon \ --exclude=config/autoload/*local* \ + --exclude=config/test \ --exclude=**/test* \ --exclude=build* cd "${builtcontent}" diff --git a/config/config.php b/config/config.php index 1c87f66e..9b28cf82 100644 --- a/config/config.php +++ b/config/config.php @@ -6,6 +6,7 @@ namespace Shlinkio\Shlink; use Acelaya\ExpressiveErrorHandler; use Zend\ConfigAggregator; use Zend\Expressive; +use function Shlinkio\Shlink\Common\env; return (new ConfigAggregator\ConfigAggregator([ Expressive\ConfigProvider::class, @@ -21,4 +22,7 @@ return (new ConfigAggregator\ConfigAggregator([ Rest\ConfigProvider::class, new ConfigAggregator\PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'), new ConfigAggregator\ZendConfigProvider('config/params/{generated_config.php,*.config.{php,json}}'), + env('APP_ENV') === 'test' + ? new ConfigAggregator\PhpFileProvider('config/test/*.global.php') + : new ConfigAggregator\ArrayProvider([]), ], 'data/cache/app_config.php'))->getMergedConfig(); diff --git a/db_tests_bootstrap.php b/config/test/bootstrap_db_tests.php similarity index 76% rename from db_tests_bootstrap.php rename to config/test/bootstrap_db_tests.php index 4bf09ba9..4a1bce4d 100644 --- a/db_tests_bootstrap.php +++ b/config/test/bootstrap_db_tests.php @@ -2,7 +2,7 @@ declare(strict_types=1); use Psr\Container\ContainerInterface; -use ShlinkioTest\Shlink\Common\DbUnit\DatabaseTestCase; +use ShlinkioTest\Shlink\Common\DbTest\DatabaseTestCase; use Symfony\Component\Process\Process; // Create an empty .env file @@ -16,10 +16,10 @@ if (file_exists($shlinkDbPath)) { } /** @var ContainerInterface $container */ -$container = require __DIR__ . '/config/test-container.php'; +$container = require __DIR__ . '/../test-container.php'; // Create database -$process = new Process(['vendor/bin/doctrine', 'orm:schema-tool:create', '--no-interaction', '-q', '--test'], __DIR__); +$process = new Process(['vendor/bin/doctrine', 'orm:schema-tool:create', '--no-interaction', '-q', '--test']); $process->inheritEnvironmentVariables() ->mustRun(); diff --git a/config/test/swoole.global.php b/config/test/swoole.global.php new file mode 100644 index 00000000..f922dd7a --- /dev/null +++ b/config/test/swoole.global.php @@ -0,0 +1,12 @@ + [ + 'swoole-http-server' => [ + 'port' => 9999, + ], + ], + +]; diff --git a/module/Common/test-db/ApiTest/ApiTestCase.php b/module/Common/test-db/ApiTest/ApiTestCase.php new file mode 100644 index 00000000..e947eba9 --- /dev/null +++ b/module/Common/test-db/ApiTest/ApiTestCase.php @@ -0,0 +1,10 @@ +getEntityManager()->createQueryBuilder(); $qb->delete($entityClass, 'x'); $qb->getQuery()->execute(); } - // Clear entity manager $this->getEntityManager()->clear(); } } diff --git a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php index c7f809b9..ae42e813 100644 --- a/module/Core/test-db/Repository/ShortUrlRepositoryTest.php +++ b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php @@ -11,7 +11,7 @@ use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Model\ShortUrlMeta; use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Repository\ShortUrlRepository; -use ShlinkioTest\Shlink\Common\DbUnit\DatabaseTestCase; +use ShlinkioTest\Shlink\Common\DbTest\DatabaseTestCase; use function count; class ShortUrlRepositoryTest extends DatabaseTestCase diff --git a/module/Core/test-db/Repository/TagRepositoryTest.php b/module/Core/test-db/Repository/TagRepositoryTest.php index 9292753c..fb43bfe1 100644 --- a/module/Core/test-db/Repository/TagRepositoryTest.php +++ b/module/Core/test-db/Repository/TagRepositoryTest.php @@ -5,7 +5,7 @@ namespace ShlinkioTest\Shlink\Core\Repository; use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Repository\TagRepository; -use ShlinkioTest\Shlink\Common\DbUnit\DatabaseTestCase; +use ShlinkioTest\Shlink\Common\DbTest\DatabaseTestCase; class TagRepositoryTest extends DatabaseTestCase { diff --git a/module/Core/test-db/Repository/VisitRepositoryTest.php b/module/Core/test-db/Repository/VisitRepositoryTest.php index 1841f5a0..ed059a37 100644 --- a/module/Core/test-db/Repository/VisitRepositoryTest.php +++ b/module/Core/test-db/Repository/VisitRepositoryTest.php @@ -10,7 +10,7 @@ use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Entity\VisitLocation; use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Repository\VisitRepository; -use ShlinkioTest\Shlink\Common\DbUnit\DatabaseTestCase; +use ShlinkioTest\Shlink\Common\DbTest\DatabaseTestCase; use function sprintf; class VisitRepositoryTest extends DatabaseTestCase diff --git a/phpunit-db.xml b/phpunit-db.xml index f514afd9..eab4be28 100644 --- a/phpunit-db.xml +++ b/phpunit-db.xml @@ -1,9 +1,10 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.5/phpunit.xsd" + bootstrap="./config/test/bootstrap_db_tests.php" + colors="true" +> ./module/*/test-db