diff --git a/composer.json b/composer.json index 31854436..4e0d2e82 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,7 @@ }, "require-dev": { "filp/whoops": "^2.0", + "phpunit/dbunit": "^3.0", "phpunit/phpunit": "^6.0", "slevomat/coding-standard": "^4.0", "squizlabs/php_codesniffer": "^3.1", @@ -69,7 +70,10 @@ "ShlinkioTest\\Shlink\\CLI\\": "module/CLI/test", "ShlinkioTest\\Shlink\\Rest\\": "module/Rest/test", "ShlinkioTest\\Shlink\\Core\\": "module/Core/test", - "ShlinkioTest\\Shlink\\Common\\": "module/Common/test" + "ShlinkioTest\\Shlink\\Common\\": [ + "module/Common/test", + "module/Common/test-func" + ] } }, "scripts": { diff --git a/func_tests_bootstrap.php b/func_tests_bootstrap.php new file mode 100644 index 00000000..e3c624da --- /dev/null +++ b/func_tests_bootstrap.php @@ -0,0 +1,29 @@ +setAllowOverride(true); +$config = $sm->get('config'); +$config['entity_manager']['connection'] = [ + 'driver' => 'pdo_sqlite', + 'memory' => true, +]; +$sm->setService('config', $config); + +$process = new Process('vendor/bin/doctrine-migrations migrations:migrate --no-interaction -q', __DIR__); +$process->inheritEnvironmentVariables() + ->setTimeout(60 * 5) // 5 minutes + ->mustRun(); + +DatabaseTestCase::$em = $sm->get(EntityManagerInterface::class); diff --git a/module/Common/test-func/DbUnit/DatabaseTestCase.php b/module/Common/test-func/DbUnit/DatabaseTestCase.php new file mode 100644 index 00000000..58a10bdc --- /dev/null +++ b/module/Common/test-func/DbUnit/DatabaseTestCase.php @@ -0,0 +1,58 @@ +getConnection()->getWrappedConnection(); + return self::$conn = $this->createDefaultDBConnection($pdo, static::$em->getConnection()->getDatabase()); + } + + public function getDataSet(): DataSet + { + return $this->createArrayDataSet([]); + } + + protected function getEntityManager(): EntityManagerInterface + { + return static::$em; + } + + public function tearDown() + { + // Empty all entity tables defined by this test after each test + foreach (static::ENTITIES_TO_EMPTY as $entityClass) { + $qb = $this->getEntityManager()->createQueryBuilder(); + $qb->delete($entityClass, 'x'); + $qb->getQuery()->execute(); + } + + // Clear entity manager + $this->getEntityManager()->clear(); + } +}