diff --git a/composer.json b/composer.json index d78860a1..7f519c51 100644 --- a/composer.json +++ b/composer.json @@ -111,7 +111,7 @@ ], "test:unit": "phpdbg -qrr vendor/bin/phpunit --order-by=random --coverage-php build/coverage-unit.cov", "test:unit:ci": "phpdbg -qrr vendor/bin/phpunit --order-by=random --coverage-php build/coverage-unit.cov --coverage-clover=build/clover.xml --coverage-xml=build/coverage-xml --log-junit=build/phpunit.junit.xml", - "test:db": "phpdbg -qrr vendor/bin/phpunit --order-by=random -c phpunit-db.xml --coverage-php build/coverage-db.cov", + "test:db": "APP_ENV=test phpdbg -qrr vendor/bin/phpunit --order-by=random -c phpunit-db.xml --coverage-php build/coverage-db.cov", "test:pretty": [ "@test", diff --git a/config/cli-config.php b/config/cli-config.php index 774b3412..3c80ee16 100644 --- a/config/cli-config.php +++ b/config/cli-config.php @@ -6,18 +6,8 @@ use Doctrine\ORM\Tools\Console\ConsoleRunner; use Interop\Container\ContainerInterface; use Zend\ServiceManager\ServiceManager; -// If the "--test" flag was provided, we are on a test environment -$isTest = false; -foreach ($_SERVER['argv'] as $i => $arg) { - if ($arg === '--test') { - unset($_SERVER['argv'][$i]); - $isTest = true; - break; - } -} - /** @var ContainerInterface|ServiceManager $container */ -$container = $isTest ? include __DIR__ . '/test-container.php' : include __DIR__ . '/container.php'; +$container = include __DIR__ . '/container.php'; $em = $container->get(EntityManager::class); return ConsoleRunner::createHelperSet($em); diff --git a/config/test-container.php b/config/test-container.php deleted file mode 100644 index 8a3f4606..00000000 --- a/config/test-container.php +++ /dev/null @@ -1,14 +0,0 @@ -setAllowOverride(true); -$config = $container->get('config'); -$config['entity_manager']['connection'] = [ - 'driver' => 'pdo_sqlite', - 'path' => realpath(sys_get_temp_dir()) . '/shlink-tests.db', -]; -$container->setService('config', $config); - -return $container; diff --git a/config/test/bootstrap_db_tests.php b/config/test/bootstrap_db_tests.php index 4a1bce4d..2639d152 100644 --- a/config/test/bootstrap_db_tests.php +++ b/config/test/bootstrap_db_tests.php @@ -1,26 +1,19 @@ inheritEnvironmentVariables() - ->mustRun(); - -DatabaseTestCase::$em = $container->get('em'); +$container->get(TestHelper::class)->createTestDb(); +DbTest\DatabaseTestCase::$em = $container->get('em'); diff --git a/config/test/swoole.global.php b/config/test/swoole.global.php deleted file mode 100644 index f922dd7a..00000000 --- a/config/test/swoole.global.php +++ /dev/null @@ -1,12 +0,0 @@ - [ - 'swoole-http-server' => [ - 'port' => 9999, - ], - ], - -]; diff --git a/config/test/test_config.global.php b/config/test/test_config.global.php new file mode 100644 index 00000000..8757bb34 --- /dev/null +++ b/config/test/test_config.global.php @@ -0,0 +1,31 @@ + [ + 'swoole-http-server' => [ + 'port' => 9999, + ], + ], + + 'dependencies' => [ + 'factories' => [ + Common\TestHelper::class => InvokableFactory::class, + ], + ], + + 'entity_manager' => [ + 'connection' => [ + 'driver' => 'pdo_sqlite', + 'path' => realpath(sys_get_temp_dir()) . '/shlink-tests.db', + ], + ], + +]; diff --git a/module/Common/test-db/TestHelper.php b/module/Common/test-db/TestHelper.php new file mode 100644 index 00000000..634456fc --- /dev/null +++ b/module/Common/test-db/TestHelper.php @@ -0,0 +1,25 @@ +inheritEnvironmentVariables() + ->mustRun(); + } +}