Let the tests replace the database connection class.
This commit is contained in:
+7
-2
@@ -1,8 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once(__DIR__ . '/config.lib.php');
|
require_once(__DIR__ . '/config.lib.php');
|
||||||
global $db;
|
global $db;
|
||||||
|
/*
|
||||||
|
* The class of the connection that open_db() makes. It is always mysqli
|
||||||
|
* on the site; the tests put a fake class in the global $db_class.
|
||||||
|
*/
|
||||||
function open_db($state) {
|
function open_db($state) {
|
||||||
global $db;
|
global $db, $db_class;
|
||||||
if ($state == 'open') {
|
if ($state == 'open') {
|
||||||
if (!$db) {
|
if (!$db) {
|
||||||
$hostname = config('DB_HOST', 'localhost');
|
$hostname = config('DB_HOST', 'localhost');
|
||||||
@@ -11,7 +15,8 @@ function open_db($state) {
|
|||||||
$db_name = config('DB_NAME');
|
$db_name = config('DB_NAME');
|
||||||
// PHP 8.1+ throws exceptions by default; keep the old return-value checks working
|
// PHP 8.1+ throws exceptions by default; keep the old return-value checks working
|
||||||
mysqli_report(MYSQLI_REPORT_OFF);
|
mysqli_report(MYSQLI_REPORT_OFF);
|
||||||
$db = new mysqli($hostname, $view_user, $view_pass, $db_name);
|
$class = $db_class ?? 'mysqli';
|
||||||
|
$db = new $class($hostname, $view_user, $view_pass, $db_name);
|
||||||
if ($db->connect_error) {
|
if ($db->connect_error) {
|
||||||
$detail = 'connect error (' . $db->connect_errno . ') ' . $db->connect_error;
|
$detail = 'connect error (' . $db->connect_errno . ') ' . $db->connect_error;
|
||||||
$db = NULL;
|
$db = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user