3 namespace Drupal\Tests\drupalmoduleupgrader\Unit;
5 use Drupal\Core\Database\Driver\sqlite\Connection;
8 * A trait for tests that need a database.
10 trait SQLiteDatabaseTrait {
13 * @var \Drupal\Core\Database\Connection
17 protected function initDB() {
18 if (empty($this->db)) {
19 // In-memory databases will cease to exist as soon as the connection
20 // is closed, which is...convenient as hell!
21 $db = new \PDO('sqlite::memory:');
22 // Throw exceptions when things go awry.
23 $db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
24 $this->db = new Connection($db, []);