2023-01-15 15:12:25 +00:00
|
|
|
<?php
|
2024-08-24 12:31:41 +00:00
|
|
|
|
|
|
|
// Copyright (C) 2010-2024, the Friendica project
|
|
|
|
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
2023-01-15 15:12:25 +00:00
|
|
|
|
|
|
|
namespace Friendica\Test\Util;
|
|
|
|
|
2023-02-04 23:15:01 +00:00
|
|
|
use Friendica\Core\Config\Model\ReadOnlyFileConfig;
|
2023-01-15 15:12:25 +00:00
|
|
|
use Friendica\Core\Config\Util\ConfigFileManager;
|
|
|
|
use Friendica\Core\Config\ValueObject\Cache;
|
|
|
|
use Friendica\Database\Database;
|
|
|
|
use Friendica\Database\Definition\DbaDefinition;
|
|
|
|
use Friendica\Database\Definition\ViewDefinition;
|
2024-12-13 22:10:30 +00:00
|
|
|
use Friendica\Test\DatabaseTestCaseTrait;
|
2023-01-15 15:12:25 +00:00
|
|
|
use Friendica\Test\Util\Database\StaticDatabase;
|
|
|
|
use Friendica\Util\Profiler;
|
2023-01-15 21:31:19 +00:00
|
|
|
use Psr\Log\NullLogger;
|
2023-01-15 15:12:25 +00:00
|
|
|
|
|
|
|
trait CreateDatabaseTrait
|
|
|
|
{
|
|
|
|
use DatabaseTestTrait;
|
|
|
|
use VFSTrait;
|
|
|
|
|
2023-02-12 12:09:05 +00:00
|
|
|
/** @var Database|null */
|
|
|
|
protected $dba = null;
|
|
|
|
|
2023-01-15 15:12:25 +00:00
|
|
|
public function getDbInstance(): Database
|
|
|
|
{
|
2023-02-12 12:09:05 +00:00
|
|
|
if (isset($this->dba)) {
|
|
|
|
return $this->dba;
|
|
|
|
}
|
|
|
|
|
2023-01-15 15:12:25 +00:00
|
|
|
$configFileManager = new ConfigFileManager($this->root->url(), $this->root->url() . '/config/', $this->root->url() . '/static/');
|
2023-02-04 23:15:01 +00:00
|
|
|
$config = new ReadOnlyFileConfig(new Cache([
|
2023-01-15 15:12:25 +00:00
|
|
|
'database' => [
|
|
|
|
'disable_pdo' => true
|
|
|
|
],
|
|
|
|
]));
|
|
|
|
|
2023-02-04 23:15:01 +00:00
|
|
|
$database = new StaticDatabase($config, (new DbaDefinition($this->root->url()))->load(), (new ViewDefinition($this->root->url()))->load());
|
2023-01-15 15:12:25 +00:00
|
|
|
$database->setTestmode(true);
|
|
|
|
|
|
|
|
return $database;
|
|
|
|
}
|
|
|
|
}
|