Browse Source

Fix remaining tests

microsub
J. King 5 years ago
parent
commit
f3b0c791f8
  1. 22
      tests/cases/Db/BaseStatement.php
  2. 16
      tests/cases/Db/MySQL/TestDriver.php
  3. 2
      tests/cases/Db/MySQL/TestStatement.php

22
tests/cases/Db/BaseStatement.php

@ -90,25 +90,23 @@ abstract class BaseStatement extends \JKingWeb\Arsse\Test\AbstractTest {
public function testBindMultipleValues() {
$exp = [
'one' => 1,
'two' => 2,
'one' => "A",
'two' => "B",
];
$exp = static::$stringOutput ? $this->stringify($exp) : $exp;
$s = new $this->statementClass(...$this->makeStatement("SELECT ? as one, ? as two", ["int", "int"]));
$val = $s->runArray([1,2])->getRow();
$s = new $this->statementClass(...$this->makeStatement("SELECT ? as one, ? as two", ["str", "str"]));
$val = $s->runArray(["A", "B"])->getRow();
$this->assertSame($exp, $val);
}
public function testBindRecursively() {
$exp = [
'one' => 1,
'two' => 2,
'three' => 3,
'four' => 4,
'one' => "A",
'two' => "B",
'three' => "C",
'four' => "D",
];
$exp = static::$stringOutput ? $this->stringify($exp) : $exp;
$s = new $this->statementClass(...$this->makeStatement("SELECT ? as one, ? as two, ? as three, ? as four", ["int", ["int", "int"], "int"]));
$val = $s->runArray([1, [2, 3], 4])->getRow();
$s = new $this->statementClass(...$this->makeStatement("SELECT ? as one, ? as two, ? as three, ? as four", ["str", ["str", "str"], "str"]));
$val = $s->runArray(["A", ["B", "C"], "D"])->getRow();
$this->assertSame($exp, $val);
}

16
tests/cases/Db/MySQL/TestDriver.php

@ -18,18 +18,14 @@ class TestDriver extends \JKingWeb\Arsse\TestCase\Db\BaseDriver {
protected static $insertDefaultValues = "INSERT INTO arsse_test(id) values(default)";
protected function exec($q): bool {
if (is_array($q)) {
$q = implode("; ", $q);
if (!is_array($q)) {
$q = [$q];
}
static::$interface->multi_query($q);
$e = null;
do {
if (!$e && static::$interface->sqlstate !== "00000") {
$e = new \Exception(static::$interface->error);
foreach ($q as $query) {
static::$interface->query($query);
if (static::$interface->sqlstate !== "00000") {
throw new \Exception(static::$interface->error);
}
} while (static::$interface->more_results() && static::$interface->next_result());
if ($e) {
throw $e;
}
return true;
}

2
tests/cases/Db/MySQL/TestStatement.php

@ -25,6 +25,8 @@ class TestStatement extends \JKingWeb\Arsse\TestCase\Db\BaseStatement {
return "'".\IntlChar::chr((int) $match[1])."'";
}
return $value;
case "datetime":
return "cast($value as datetime(0))";
default:
return $value;
}

Loading…
Cancel
Save