Browse Source

Fix most test failures

MySQL is still being stubborn. It may be a type-conversion issue.
dbtest
J. King 2 years ago
parent
commit
2822864a85
  1. 2
      lib/Db/MySQL/Driver.php
  2. 25
      tests/lib/AbstractTest.php
  3. 4
      tests/lib/DatabaseDrivers/MySQL.php

2
lib/Db/MySQL/Driver.php

@ -165,7 +165,7 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
$drv->report_mode = \MYSQLI_REPORT_OFF;
$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_INT_AND_FLOAT_NATIVE, true);
$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) {

25
tests/lib/AbstractTest.php

@ -415,9 +415,11 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
foreach ($info['rows'] as $r) {
$row = [];
foreach ($r as $c => $v) {
// store any date values for later comparison
if ($types[$c] === "datetime") {
$dates[] = $v;
}
// serialize to CSV, null being represented by no value
if ($v === null) {
$row[] = "";
} elseif (static::$stringOutput || is_string($v)) {
@ -435,9 +437,11 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
$data = $drv->prepare("SELECT $cols from $table")->run()->getAll();
$types = $info['columns'];
$act = [];
$extra = [];
foreach ($data as $r) {
$row = [];
foreach ($r as $c => $v) {
// account for dates which might be off by one second
if ($types[$c] === "datetime") {
if (array_search($v, $dates, true) === false) {
$v = Date::transform(Date::sub("PT1S", $v), "sql");
@ -457,8 +461,27 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
$row[] = (string) $v;
}
}
$act[] = implode(",", $row);
$row = implode(",", $row);
// now search for the actual output row in the expected output
$found = array_keys($exp, $row, true);
foreach ($found as $k) {
if(!isset($act[$k])) {
$act[$k] = $row;
// skip to the next row
continue 2;
}
}
// if the row was not found, add it to a buffer which will be added to the actual output once all found rows are processed
$extra[] = $row;
}
// add any unfound rows to the end of the actual array
$base = sizeof($exp) + 1;
foreach ($extra as $k => $v) {
$act[$base + $k] = $v;
}
// sort the actual output by keys
ksort($act);
// finally perform the comparison to be shown to the tester
$this->assertSame($exp, $act, "Actual table $table does not match expectations");
}
}

4
tests/lib/DatabaseDrivers/MySQL.php

@ -16,7 +16,7 @@ trait MySQL {
protected static $dbResultClass = \JKingWeb\Arsse\Db\MySQL\Result::class;
protected static $dbStatementClass = \JKingWeb\Arsse\Db\MySQL\Statement::class;
protected static $dbDriverClass = \JKingWeb\Arsse\Db\MySQL\Driver::class;
protected static $stringOutput = true;
protected static $stringOutput = false;
public static function dbInterface() {
if (!class_exists("mysqli")) {
@ -25,7 +25,7 @@ trait MySQL {
$drv = new \mysqli_driver;
$drv->report_mode = \MYSQLI_REPORT_OFF;
$d = mysqli_init();
$d->options(\MYSQLI_OPT_INT_AND_FLOAT_NATIVE, false);
$d->options(\MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);
$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) {

Loading…
Cancel
Save