2018-09-16 14:08:09 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit;
|
|
|
|
|
|
|
|
use Engelsystem\Database\Database;
|
|
|
|
use Engelsystem\Database\Migration\Migrate;
|
|
|
|
use Engelsystem\Database\Migration\MigrationServiceProvider;
|
|
|
|
use Illuminate\Database\Capsule\Manager as CapsuleManager;
|
|
|
|
use PDO;
|
|
|
|
|
|
|
|
trait HasDatabase
|
|
|
|
{
|
|
|
|
/** @var Database */
|
|
|
|
protected $database;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup in memory database
|
|
|
|
*/
|
|
|
|
protected function initDatabase()
|
|
|
|
{
|
|
|
|
$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);
|
|
|
|
$this->app->register(MigrationServiceProvider::class);
|
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(
|
|
|
|
[
|
|
|
|
['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'],
|
2019-11-27 23:43:21 +01:00
|
|
|
]
|
|
|
|
);
|
2018-09-16 14:08:09 +02:00
|
|
|
|
|
|
|
$migration->run(__DIR__ . '/../../db/migrations');
|
|
|
|
}
|
|
|
|
}
|