Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / tests / src / Unit / SQLiteDatabaseTrait.php
1 <?php
2
3 namespace Drupal\Tests\drupalmoduleupgrader\Unit;
4
5 use Drupal\Core\Database\Driver\sqlite\Connection;
6
7 /**
8  * A trait for tests that need a database.
9  */
10 trait SQLiteDatabaseTrait {
11
12   /**
13    * @var \Drupal\Core\Database\Connection
14    */
15   protected $db;
16
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, []);
25     }
26   }
27
28 }