From 5cfa01f4d515efbbf3cb6c0e09e86b5849d0fa21 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Tue, 2 Mar 2021 11:04:21 -0500 Subject: [PATCH] Work around MySQL stupidity --- lib/Db/MySQL/Driver.php | 2 ++ tests/lib/AbstractTest.php | 6 +++++- tests/lib/DatabaseDrivers/MySQL.php | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Db/MySQL/Driver.php b/lib/Db/MySQL/Driver.php index 1c0da1e..d2c538b 100644 --- a/lib/Db/MySQL/Driver.php +++ b/lib/Db/MySQL/Driver.php @@ -164,6 +164,8 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver { protected function makeConnection(string $db, string $user, string $password, string $host, int $port, string $socket): void { $this->db = mysqli_init(); + $this->db->options(\MYSQLI_SET_CHARSET_NAME, "utf8mb4"); + $this->db->options(\MYSQLI_OPT_INT_AND_FLOAT_NATIVE, false); $this->db->options(\MYSQLI_OPT_CONNECT_TIMEOUT, ceil(Arsse::$conf->dbTimeoutConnect)); @$this->db->real_connect($host, $user, $password, $db, $port, $socket); if ($this->db->connect_errno) { diff --git a/tests/lib/AbstractTest.php b/tests/lib/AbstractTest.php index 3ed6fc4..5bfd035 100644 --- a/tests/lib/AbstractTest.php +++ b/tests/lib/AbstractTest.php @@ -324,11 +324,15 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { } public function assertResult(array $expected, Result $data): void { + $data = $data->getAll(); // stringify our expectations if necessary if (static::$stringOutput ?? false) { $expected = $this->stringify($expected); + // MySQL is extra-special and mixes strings and integers, so we cast the data, too + if ((static::$implementation ?? "") === "MySQL") { + $data = $this->stringify($data); + } } - $data = $data->getAll(); $this->assertCount(sizeof($expected), $data, "Number of result rows (".sizeof($data).") differs from number of expected rows (".sizeof($expected).")"); if (sizeof($expected)) { // make sure the expectations are consistent diff --git a/tests/lib/DatabaseDrivers/MySQL.php b/tests/lib/DatabaseDrivers/MySQL.php index 01501f1..0df43d3 100644 --- a/tests/lib/DatabaseDrivers/MySQL.php +++ b/tests/lib/DatabaseDrivers/MySQL.php @@ -21,7 +21,10 @@ trait MySQL { if (!class_exists("mysqli")) { return null; } - $d = @new \mysqli(Arsse::$conf->dbMySQLHost, Arsse::$conf->dbMySQLUser, Arsse::$conf->dbMySQLPass, Arsse::$conf->dbMySQLDb, Arsse::$conf->dbMySQLPort); + $d = mysqli_init(); + $d->options(\MYSQLI_OPT_INT_AND_FLOAT_NATIVE, false); + $d->options(\MYSQLI_SET_CHARSET_NAME, "utf8mb4"); + @$d->real_connect(Arsse::$conf->dbMySQLHost, Arsse::$conf->dbMySQLUser, Arsse::$conf->dbMySQLPass, Arsse::$conf->dbMySQLDb, Arsse::$conf->dbMySQLPort); if ($d->connect_errno) { return null; }