mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Created first common elements for functional tests
This commit is contained in:
parent
5a500a00d7
commit
d7b7db670f
3 changed files with 92 additions and 1 deletions
|
@ -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": {
|
||||
|
|
29
func_tests_bootstrap.php
Normal file
29
func_tests_bootstrap.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use ShlinkioTest\Shlink\Common\DbUnit\DatabaseTestCase;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
|
||||
// Create an empty .env file
|
||||
if (! file_exists('.env')) {
|
||||
touch('.env');
|
||||
}
|
||||
|
||||
/** @var ServiceManager $sm */
|
||||
$sm = require __DIR__ . '/config/container.php';
|
||||
$sm->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);
|
58
module/Common/test-func/DbUnit/DatabaseTestCase.php
Normal file
58
module/Common/test-func/DbUnit/DatabaseTestCase.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Common\DbUnit;
|
||||
|
||||
use Doctrine\DBAL\Driver\PDOConnection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\DbUnit\Database\Connection as DbConn;
|
||||
use PHPUnit\DbUnit\DataSet\IDataSet as DataSet;
|
||||
use PHPUnit\DbUnit\TestCase;
|
||||
|
||||
abstract class DatabaseTestCase extends TestCase
|
||||
{
|
||||
const ENTITIES_TO_EMPTY = [];
|
||||
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
public static $em;
|
||||
/**
|
||||
* @var DbConn
|
||||
*/
|
||||
private static $conn;
|
||||
|
||||
public function getConnection(): DbConn
|
||||
{
|
||||
if (isset(self::$conn)) {
|
||||
return self::$conn;
|
||||
}
|
||||
|
||||
/** @var PDOConnection $pdo */
|
||||
$pdo = static::$em->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();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue