summaryrefslogtreecommitdiff
path: root/tests/Unit/HasDatabase.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-30 19:31:14 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-30 19:33:14 +0200
commitb46207f91176cf944284c01c213d3f69075377a4 (patch)
tree3d04a46c84c8b66b2d5a56a851249fde80257e28 /tests/Unit/HasDatabase.php
parent6187eed3bb08f200050a3078bd762b5731dfbe78 (diff)
parent0b0890f425ced27b2204a046296de4cccdac4eb8 (diff)
Merge remote-tracking branch 'MyIgel/session'
Diffstat (limited to 'tests/Unit/HasDatabase.php')
-rw-r--r--tests/Unit/HasDatabase.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/Unit/HasDatabase.php b/tests/Unit/HasDatabase.php
new file mode 100644
index 00000000..d69f0a3a
--- /dev/null
+++ b/tests/Unit/HasDatabase.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace Engelsystem\Test\Unit;
+
+use Engelsystem\Application;
+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:']);
+
+ $connection = $dbManager->getConnection();
+ $connection->getPdo()->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $this->database = new Database($connection);
+
+ $app = new Application();
+ $app->instance(Database::class, $this->database);
+ $app->register(MigrationServiceProvider::class);
+
+ /** @var Migrate $migration */
+ $migration = $app->get('db.migration');
+ $migration->initMigration();
+
+ $this->database
+ ->getConnection()
+ ->table('migrations')
+ ->insert([
+ ['migration' => '2018_01_01_000001_import_install_sql'],
+ ['migration' => '2018_01_01_000002_import_update_sql'],
+ ]);
+
+ $migration->run(__DIR__ . '/../../db/migrations');
+ }
+}