2020-03-11 04:04:22 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2022-10-30 03:56:03 +09:00
|
|
|
use App\Core\GNUsocial;
|
|
|
|
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
|
|
|
|
use Doctrine\DBAL\DriverManager;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Doctrine\ORM\Tools\SchemaTool;
|
|
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
use Functional as F;
|
2020-03-11 04:04:22 +09:00
|
|
|
use Symfony\Component\Dotenv\Dotenv;
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
require \dirname(__DIR__) . '/vendor/autoload.php';
|
2020-03-11 04:04:22 +09:00
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
if (file_exists(\dirname(__DIR__) . '/config/bootstrap.php')) {
|
|
|
|
require \dirname(__DIR__) . '/config/bootstrap.php';
|
2020-05-11 05:43:15 +09:00
|
|
|
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
|
2021-10-10 17:26:18 +09:00
|
|
|
(new Dotenv())->bootEnv(\dirname(__DIR__) . '/.env');
|
2020-03-11 04:04:22 +09:00
|
|
|
}
|
2022-10-30 03:56:03 +09:00
|
|
|
|
|
|
|
global $APP_KERNEL;
|
|
|
|
|
|
|
|
if (isset($_ENV['APP_ENV'])) {
|
|
|
|
$env = $_ENV['APP_ENV'];
|
|
|
|
} elseif (isset($_SERVER['APP_ENV'])) {
|
|
|
|
$env = $_SERVER['APP_ENV'];
|
|
|
|
} else {
|
|
|
|
$env = 'test';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_ENV['APP_DEBUG'])) {
|
|
|
|
$debug = $_ENV['APP_DEBUG'];
|
|
|
|
} elseif (isset($_SERVER['APP_DEBUG'])) {
|
|
|
|
$debug = $_SERVER['APP_DEBUG'];
|
|
|
|
} else {
|
|
|
|
$debug = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ini_set('memory_limit', '1G');
|
|
|
|
|
|
|
|
$APP_KERNEL = new \App\Kernel($env, (bool) $debug);
|
|
|
|
$APP_KERNEL->boot();
|
|
|
|
|
|
|
|
$container = $APP_KERNEL->getContainer()->get('test.service_container');
|
|
|
|
|
|
|
|
$services = F\map(
|
|
|
|
(new \ReflectionClass(GNUsocial::class))->getMethod('__construct')->getParameters(),
|
|
|
|
fn ($p) => $container->get((string) $p->getType()),
|
|
|
|
);
|
|
|
|
global $GNUSOCIAL;
|
|
|
|
$GNUSOCIAL = new GNUsocial(...$services);
|
|
|
|
|
|
|
|
$doctrine = $container->get(ManagerRegistry::class);
|
|
|
|
$em = $container->get(EntityManagerInterface::class);
|
|
|
|
$connection = $doctrine->getConnection();
|
|
|
|
$params = $connection->getParams();
|
|
|
|
$tmpConnection = DriverManager::getConnection($params);
|
|
|
|
$name = $params['dbname'];
|
|
|
|
if (!\in_array($name, $tmpConnection->getSchemaManager()->listDatabases())) {
|
|
|
|
unset($params['dbname'], $params['path'], $params['url']);
|
|
|
|
$tmpConnection = DriverManager::getConnection($params);
|
|
|
|
$tmpConnection->getSchemaManager()->createDatabase($name);
|
|
|
|
|
|
|
|
$metadatas = $em->getMetadataFactory()->getAllMetadata();
|
|
|
|
$schemaTool = new SchemaTool($em);
|
|
|
|
$schemaTool->createSchema($metadatas);
|
|
|
|
|
|
|
|
$fixturesLoader = $container->get('doctrine.fixtures.loader');
|
|
|
|
$fixtures = $fixturesLoader->getFixtures();
|
|
|
|
$executor = new ORMExecutor($em);
|
|
|
|
$executor->execute($fixtures, append: true);
|
|
|
|
|
|
|
|
$tmpConnection->close();
|
|
|
|
echo "Created database {$name}\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$connection->connect();
|
|
|
|
|
|
|
|
$connection->setNestTransactionsWithSavepoints(true);
|
|
|
|
$connection->beginTransaction();
|
|
|
|
register_shutdown_function(function ($connection) {
|
|
|
|
echo 'Rolling back changes';
|
|
|
|
$connection->rollBack();
|
|
|
|
}, $connection);
|