2016-04-17 21:27:24 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-04-17 21:27:24 +03:00
|
|
|
use Doctrine\ORM\EntityManager;
|
|
|
|
use Doctrine\ORM\Tools\Console\ConsoleRunner;
|
|
|
|
use Interop\Container\ContainerInterface;
|
2017-10-23 12:20:55 +03:00
|
|
|
use Zend\ServiceManager\ServiceManager;
|
2016-04-17 21:27:24 +03:00
|
|
|
|
2017-10-23 12:20:55 +03:00
|
|
|
$isTest = false;
|
|
|
|
foreach ($_SERVER['argv'] as $i => $arg) {
|
|
|
|
if ($arg === '--test') {
|
|
|
|
unset($_SERVER['argv'][$i]);
|
|
|
|
$isTest = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var ContainerInterface|ServiceManager $container */
|
2016-07-19 17:50:02 +03:00
|
|
|
$container = include __DIR__ . '/container.php';
|
2017-10-23 12:20:55 +03:00
|
|
|
|
|
|
|
// 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',
|
2017-10-23 13:19:28 +03:00
|
|
|
'path' => realpath(sys_get_temp_dir()) . '/shlink-tests.db',
|
2017-10-23 12:20:55 +03:00
|
|
|
];
|
|
|
|
$container->setService('config', $config);
|
|
|
|
}
|
|
|
|
|
2016-04-17 21:27:24 +03:00
|
|
|
/** @var EntityManager $em */
|
|
|
|
$em = $container->get(EntityManager::class);
|
|
|
|
|
|
|
|
return ConsoleRunner::createHelperSet($em);
|