From 687d8d91a9a3688538ebd8bc00a36cb60b4b6a07 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 20 Jan 2019 21:49:07 +0100 Subject: [PATCH 1/3] Changed references to functional tests by database tests --- .travis.yml | 2 +- CHANGELOG.md | 2 +- composer.json | 24 ++++++++----------- ...ts_bootstrap.php => db_tests_bootstrap.php | 0 .../DbUnit/DatabaseTestCase.php | 0 .../Repository/ShortUrlRepositoryTest.php | 0 .../Repository/TagRepositoryTest.php | 0 .../Repository/VisitRepositoryTest.php | 0 phpunit-func.xml => phpunit-db.xml | 6 ++--- 9 files changed, 15 insertions(+), 19 deletions(-) rename func_tests_bootstrap.php => db_tests_bootstrap.php (100%) rename module/Common/{test-func => test-db}/DbUnit/DatabaseTestCase.php (100%) rename module/Core/{test-func => test-db}/Repository/ShortUrlRepositoryTest.php (100%) rename module/Core/{test-func => test-db}/Repository/TagRepositoryTest.php (100%) rename module/Core/{test-func => test-db}/Repository/VisitRepositoryTest.php (100%) rename phpunit-func.xml => phpunit-db.xml (78%) diff --git a/.travis.yml b/.travis.yml index 9e33852b..f54e3358 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ install: script: - mkdir build - - composer check + - composer ci after_success: - rm -f build/clover.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ac60d4b..24ecb700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org). +The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). ## [Unreleased] diff --git a/composer.json b/composer.json index c3257a7d..d78860a1 100644 --- a/composer.json +++ b/composer.json @@ -80,26 +80,22 @@ "ShlinkioTest\\Shlink\\Rest\\": "module/Rest/test", "ShlinkioTest\\Shlink\\Core\\": [ "module/Core/test", - "module/Core/test-func" + "module/Core/test-db" ], "ShlinkioTest\\Shlink\\Common\\": [ "module/Common/test", - "module/Common/test-func" + "module/Common/test-db" ], "ShlinkioTest\\Shlink\\Installer\\": "module/Installer/test" } }, "scripts": { - "check": [ + "ci": [ "@cs", "@stan", "@test:ci", "@infect:ci" ], - "ci": [ - "echo \"This command is DEPRECATED. Use check instead\"", - "@check" - ], "cs": "phpcs", "cs:fix": "phpcbf", @@ -107,15 +103,15 @@ "test": [ "@test:unit", - "@test:func" + "@test:db" ], "test:ci": [ "@test:unit:ci", - "@test:func" + "@test:db" ], "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:func": "phpdbg -qrr vendor/bin/phpunit --order-by=random -c phpunit-func.xml --coverage-php build/coverage-func.cov", + "test:db": "phpdbg -qrr vendor/bin/phpunit --order-by=random -c phpunit-db.xml --coverage-php build/coverage-db.cov", "test:pretty": [ "@test", @@ -123,9 +119,9 @@ ], "test:unit:pretty": "phpdbg -qrr vendor/bin/phpunit --coverage-html build/coverage --order-by=random", - "infect": "infection --threads=4 --min-msi=65 --log-verbosity=2 --only-covered", - "infect:ci": "infection --threads=4 --min-msi=65 --log-verbosity=2 --only-covered --coverage=build", - "infect:show": "infection --threads=4 --min-msi=65 --log-verbosity=2 --only-covered --show-mutations", + "infect": "infection --threads=4 --min-msi=65 --log-verbosity=default --only-covered", + "infect:ci": "infection --threads=4 --min-msi=65 --log-verbosity=default --only-covered --coverage=build", + "infect:show": "infection --threads=4 --min-msi=65 --log-verbosity=default --only-covered --show-mutations", "infect:test": [ "@test:unit:ci", "@infect:ci" @@ -141,7 +137,7 @@ "test:ci": "Runs all test suites, generating all needed reports and logs for CI envs", "test:unit": "Runs unit test suites", "test:unit:ci": "Runs unit test suites, generating all needed reports and logs for CI envs", - "test:func": "Runs functional test suites (covering entity repositories)", + "test:db": "Runs database test suites (covering entity repositories)", "test:pretty": "Runs all test suites and generates an HTML code coverage report", "test:unit:pretty": "Runs unit test suites and generates an HTML code coverage report", "infect": "Checks unit tests quality applying mutation testing", diff --git a/func_tests_bootstrap.php b/db_tests_bootstrap.php similarity index 100% rename from func_tests_bootstrap.php rename to db_tests_bootstrap.php diff --git a/module/Common/test-func/DbUnit/DatabaseTestCase.php b/module/Common/test-db/DbUnit/DatabaseTestCase.php similarity index 100% rename from module/Common/test-func/DbUnit/DatabaseTestCase.php rename to module/Common/test-db/DbUnit/DatabaseTestCase.php diff --git a/module/Core/test-func/Repository/ShortUrlRepositoryTest.php b/module/Core/test-db/Repository/ShortUrlRepositoryTest.php similarity index 100% rename from module/Core/test-func/Repository/ShortUrlRepositoryTest.php rename to module/Core/test-db/Repository/ShortUrlRepositoryTest.php diff --git a/module/Core/test-func/Repository/TagRepositoryTest.php b/module/Core/test-db/Repository/TagRepositoryTest.php similarity index 100% rename from module/Core/test-func/Repository/TagRepositoryTest.php rename to module/Core/test-db/Repository/TagRepositoryTest.php diff --git a/module/Core/test-func/Repository/VisitRepositoryTest.php b/module/Core/test-db/Repository/VisitRepositoryTest.php similarity index 100% rename from module/Core/test-func/Repository/VisitRepositoryTest.php rename to module/Core/test-db/Repository/VisitRepositoryTest.php diff --git a/phpunit-func.xml b/phpunit-db.xml similarity index 78% rename from phpunit-func.xml rename to phpunit-db.xml index f06c11ee..f514afd9 100644 --- a/phpunit-func.xml +++ b/phpunit-db.xml @@ -2,11 +2,11 @@ - - ./module/*/test-func + + ./module/*/test-db From 284de28f768d329a7d0f81c6e7fcd965c445cc56 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 20 Jan 2019 22:08:32 +0100 Subject: [PATCH 2/3] Removed duplicated code to define testing database connection params --- config/cli-config.php | 16 ++-------------- config/test-container.php | 14 ++++++++++++++ db_tests_bootstrap.php | 15 ++++----------- 3 files changed, 20 insertions(+), 25 deletions(-) create mode 100644 config/test-container.php diff --git a/config/cli-config.php b/config/cli-config.php index 59373bbd..774b3412 100644 --- a/config/cli-config.php +++ b/config/cli-config.php @@ -6,6 +6,7 @@ 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') { @@ -16,20 +17,7 @@ foreach ($_SERVER['argv'] as $i => $arg) { } /** @var ContainerInterface|ServiceManager $container */ -$container = include __DIR__ . '/container.php'; - -// If in testing env, override DB connection to use an in-memory sqlite database -if ($isTest) { - $container->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); -} - -/** @var EntityManager $em */ +$container = $isTest ? include __DIR__ . '/test-container.php' : 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 new file mode 100644 index 00000000..8a3f4606 --- /dev/null +++ b/config/test-container.php @@ -0,0 +1,14 @@ +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/db_tests_bootstrap.php b/db_tests_bootstrap.php index 5f44c7c5..4bf09ba9 100644 --- a/db_tests_bootstrap.php +++ b/db_tests_bootstrap.php @@ -1,9 +1,9 @@ setAllowOverride(true); -$config = $sm->get('config'); -$config['entity_manager']['connection'] = [ - 'driver' => 'pdo_sqlite', - 'path' => $shlinkDbPath, -]; -$sm->setService('config', $config); +/** @var ContainerInterface $container */ +$container = require __DIR__ . '/config/test-container.php'; // Create database $process = new Process(['vendor/bin/doctrine', 'orm:schema-tool:create', '--no-interaction', '-q', '--test'], __DIR__); $process->inheritEnvironmentVariables() ->mustRun(); -DatabaseTestCase::$em = $sm->get('em'); +DatabaseTestCase::$em = $container->get('em'); From 1aaedb8d900f364500157a726067061fa11ea63a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 21 Jan 2019 21:27:16 +0100 Subject: [PATCH 3/3] Udated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24ecb700..d570c89d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this * [#320](https://github.com/shlinkio/shlink/issues/320) Replaced query builder by plain DQL for all queries which do not need to be dynamically generated. * [#330](https://github.com/shlinkio/shlink/issues/330) No longer allow failures on PHP 7.3 envs during project CI build. +* [#335](https://github.com/shlinkio/shlink/issues/335) Renamed functional test suite to database test suite, since that better describes what it actually does. #### Deprecated