Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / tests / src / Unit / SQLiteDatabaseTrait.php
diff --git a/web/modules/contrib/drupalmoduleupgrader/tests/src/Unit/SQLiteDatabaseTrait.php b/web/modules/contrib/drupalmoduleupgrader/tests/src/Unit/SQLiteDatabaseTrait.php
new file mode 100644 (file)
index 0000000..4a9b692
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+namespace Drupal\Tests\drupalmoduleupgrader\Unit;
+
+use Drupal\Core\Database\Driver\sqlite\Connection;
+
+/**
+ * A trait for tests that need a database.
+ */
+trait SQLiteDatabaseTrait {
+
+  /**
+   * @var \Drupal\Core\Database\Connection
+   */
+  protected $db;
+
+  protected function initDB() {
+    if (empty($this->db)) {
+      // In-memory databases will cease to exist as soon as the connection
+      // is closed, which is...convenient as hell!
+      $db = new \PDO('sqlite::memory:');
+      // Throw exceptions when things go awry.
+      $db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
+      $this->db = new Connection($db, []);
+    }
+  }
+
+}