2018-09-16 14:08:09 +02:00
|
|
|
<?php
|
|
|
|
|
2023-02-03 20:41:59 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-09-16 14:08:09 +02:00
|
|
|
namespace Engelsystem\Test\Unit;
|
|
|
|
|
|
|
|
use Engelsystem\Database\Database;
|
|
|
|
use Engelsystem\Database\Migration\Migrate;
|
|
|
|
use Engelsystem\Database\Migration\MigrationServiceProvider;
|
2021-05-23 11:24:01 +02:00
|
|
|
use Engelsystem\Http\Request;
|
2018-09-16 14:08:09 +02:00
|
|
|
use Illuminate\Database\Capsule\Manager as CapsuleManager;
|
2023-04-01 14:23:52 +02:00
|
|
|
use Illuminate\Database\Connection;
|
2018-09-16 14:08:09 +02:00
|
|
|
use PDO;
|
2021-05-23 11:24:01 +02:00
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
2018-09-16 14:08:09 +02:00
|
|
|
|
|
|
|
trait HasDatabase
|
|
|
|
{
|
2022-12-15 19:50:56 +01:00
|
|
|
protected Database $database;
|
2018-09-16 14:08:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup in memory database
|
|
|
|
*/
|
2022-12-14 19:15:20 +01:00
|
|
|
protected function initDatabase(): void
|
2018-09-16 14:08:09 +02:00
|
|
|
{
|
|
|
|
$dbManager = new CapsuleManager();
|
|
|
|
$dbManager->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);
|
2018-09-24 14:19:13 +02:00
|
|
|
$dbManager->bootEloquent();
|
2018-09-16 14:08:09 +02:00
|
|
|
|
|
|
|
$connection = $dbManager->getConnection();
|
|
|
|
$connection->getPdo()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
$this->database = new Database($connection);
|
|
|
|
|
2019-10-08 13:57:50 +02:00
|
|
|
$this->app->instance(Database::class, $this->database);
|
2023-04-01 14:23:52 +02:00
|
|
|
$this->app->instance(Connection::class, $connection);
|
2019-10-08 13:57:50 +02:00
|
|
|
$this->app->register(MigrationServiceProvider::class);
|
2018-09-16 14:08:09 +02:00
|
|
|
|
2021-05-23 11:24:01 +02:00
|
|
|
$this->app->instance(ServerRequestInterface::class, new Request());
|
|
|
|
|
2018-09-16 14:08:09 +02:00
|
|
|
/** @var Migrate $migration */
|
2019-10-08 13:57:50 +02:00
|
|
|
$migration = $this->app->get('db.migration');
|
2018-09-16 14:08:09 +02:00
|
|
|
$migration->initMigration();
|
|
|
|
|
|
|
|
$this->database
|
|
|
|
->getConnection()
|
|
|
|
->table('migrations')
|
2019-11-27 23:43:21 +01:00
|
|
|
->insert(
|
|
|
|
[
|
2020-09-12 21:27:40 +02:00
|
|
|
// Migrations that can be skipped as they only use legacy tables
|
2019-11-27 23:43:21 +01:00
|
|
|
['migration' => '2018_01_01_000001_import_install_sql'],
|
|
|
|
['migration' => '2018_01_01_000002_import_update_sql'],
|
|
|
|
['migration' => '2018_01_01_000003_fix_old_tables'],
|
|
|
|
['migration' => '2018_01_01_000004_cleanup_group_privileges'],
|
|
|
|
['migration' => '2018_01_01_000005_add_angel_supporter_permissions'],
|
|
|
|
['migration' => '2018_12_27_000000_fix_missing_arrival_dates'],
|
|
|
|
['migration' => '2019_09_07_000000_migrate_admin_schedule_permissions'],
|
2020-04-07 19:36:48 +02:00
|
|
|
['migration' => '2020_04_07_000000_change_mysql_database_encoding_to_utf8mb4'],
|
2020-09-12 21:27:40 +02:00
|
|
|
['migration' => '2020_09_12_000000_create_welcome_angel_permissions_group'],
|
2020-12-29 00:28:37 +01:00
|
|
|
['migration' => '2020_12_28_000000_oauth_set_identifier_binary'],
|
2023-10-23 00:40:49 +02:00
|
|
|
['migration' => '2021_05_23_000000_create_first_user'],
|
|
|
|
['migration' => '2021_05_23_000000_set_admin_password'],
|
2021-09-24 20:28:51 +02:00
|
|
|
['migration' => '2021_08_26_000000_add_shirt_edit_permissions'],
|
2021-11-27 11:43:53 +01:00
|
|
|
['migration' => '2021_10_12_000000_add_shifts_description'],
|
2022-01-01 16:21:40 +01:00
|
|
|
['migration' => '2021_12_30_000000_remove_admin_news_html_privilege'],
|
2022-06-07 13:12:26 +02:00
|
|
|
['migration' => '2022_06_02_000000_create_voucher_edit_permission'],
|
2022-06-03 21:46:16 +02:00
|
|
|
['migration' => '2022_06_03_000000_shifts_add_transaction_id'],
|
2019-07-28 15:33:01 +02:00
|
|
|
['migration' => '2022_07_21_000000_fix_old_groups_table_id_and_name'],
|
2022-10-21 22:20:06 +02:00
|
|
|
['migration' => '2022_10_21_000000_add_hide_register_to_angeltypes'],
|
2022-11-06 13:57:05 +01:00
|
|
|
['migration' => '2022_11_06_000000_shifttype_remove_angeltype'],
|
2019-11-27 23:43:21 +01:00
|
|
|
]
|
|
|
|
);
|
2018-09-16 14:08:09 +02:00
|
|
|
|
|
|
|
$migration->run(__DIR__ . '/../../db/migrations');
|
|
|
|
}
|
|
|
|
}
|