Browse Source
Three test failures remain, but these are minor and will be resolved soon. Handling of binary data is also broken, but given that this works fine with the PDO driver, there is presumably some correct method.microsub
J. King
5 years ago
14 changed files with 215 additions and 33 deletions
@ -0,0 +1,21 @@ |
|||
<?php |
|||
/** @license MIT |
|||
* Copyright 2017 J. King, Dustin Wilson et al. |
|||
* See LICENSE and AUTHORS files for details */ |
|||
|
|||
declare(strict_types=1); |
|||
namespace JKingWeb\Arsse\TestCase\Db\MySQL; |
|||
|
|||
/** |
|||
* @group slow |
|||
* @group coverageOptional |
|||
* @covers \JKingWeb\Arsse\Database<extended> |
|||
* @covers \JKingWeb\Arsse\Misc\Query<extended> |
|||
*/ |
|||
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base { |
|||
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQL; |
|||
|
|||
protected function nextID(string $table): int { |
|||
return (int) (static::$drv->query("SELECT auto_increment from information_schema.tables where table_name = '$table'")->getValue() ?? 1); |
|||
} |
|||
} |
@ -0,0 +1,50 @@ |
|||
<?php |
|||
/** @license MIT |
|||
* Copyright 2017 J. King, Dustin Wilson et al. |
|||
* See LICENSE and AUTHORS files for details */ |
|||
|
|||
declare(strict_types=1); |
|||
namespace JKingWeb\Arsse\TestCase\Db\MySQL; |
|||
|
|||
/** |
|||
* @group slow |
|||
* @covers \JKingWeb\Arsse\Db\MySQL\Driver<extended> */ |
|||
class TestDriver extends \JKingWeb\Arsse\TestCase\Db\BaseDriver { |
|||
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQL; |
|||
|
|||
protected $create = "CREATE TABLE arsse_test(id bigint auto_increment primary key)"; |
|||
protected $lock = ["SET lock_wait_timeout = 1", "LOCK TABLES arsse_meta WRITE"]; |
|||
protected $setVersion = "UPDATE arsse_meta set value = '#' where `key` = 'schema_version'"; |
|||
protected static $insertDefaultValues = "INSERT INTO arsse_test(id) values(default)"; |
|||
|
|||
protected function exec($q): bool { |
|||
if (is_array($q)) { |
|||
$q = implode("; ", $q); |
|||
} |
|||
static::$interface->multi_query($q); |
|||
$e = null; |
|||
do { |
|||
if (!$e && static::$interface->sqlstate !== "00000") { |
|||
$e = new \Exception(static::$interface->error); |
|||
} |
|||
} while (static::$interface->more_results() && static::$interface->next_result()); |
|||
if ($e) { |
|||
throw $e; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
protected function query(string $q) { |
|||
$r = static::$interface->query($q); |
|||
if ($r) { |
|||
$row = $r->fetch_row(); |
|||
$r->free(); |
|||
if ($row) { |
|||
return $row[0]; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
<?php |
|||
/** @license MIT |
|||
* Copyright 2017 J. King, Dustin Wilson et al. |
|||
* See LICENSE and AUTHORS files for details */ |
|||
|
|||
declare(strict_types=1); |
|||
namespace JKingWeb\Arsse\TestCase\Db\MySQL; |
|||
|
|||
use JKingWeb\Arsse\Test\DatabaseInformation; |
|||
|
|||
/** |
|||
* @group slow |
|||
* @covers \JKingWeb\Arsse\Db\MySQL\Result<extended> |
|||
*/ |
|||
class TestResult extends \JKingWeb\Arsse\TestCase\Db\BaseResult { |
|||
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQL; |
|||
|
|||
protected static $createMeta = "CREATE TABLE arsse_meta(`key` varchar(255) primary key not null, value text)"; |
|||
protected static $createTest = "CREATE TABLE arsse_test(id bigint auto_increment primary key)"; |
|||
protected static $insertDefault = "INSERT INTO arsse_test(id) values(default)"; |
|||
|
|||
protected function makeResult(string $q): array { |
|||
$r = static::$interface->query($q); |
|||
$rows = static::$interface->affected_rows; |
|||
$id = static::$interface->insert_id; |
|||
return [$r, [$rows, $id]]; |
|||
} |
|||
} |
@ -0,0 +1,32 @@ |
|||
<?php |
|||
/** @license MIT |
|||
* Copyright 2017 J. King, Dustin Wilson et al. |
|||
* See LICENSE and AUTHORS files for details */ |
|||
|
|||
declare(strict_types=1); |
|||
namespace JKingWeb\Arsse\TestCase\Db\MySQL; |
|||
|
|||
/** |
|||
* @group slow |
|||
* @covers \JKingWeb\Arsse\Db\MySQL\Statement<extended> */ |
|||
class TestStatement extends \JKingWeb\Arsse\TestCase\Db\BaseStatement { |
|||
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQL; |
|||
|
|||
protected function makeStatement(string $q, array $types = []): array { |
|||
return [static::$interface, $q, $types]; |
|||
} |
|||
|
|||
protected function decorateTypeSyntax(string $value, string $type): string { |
|||
switch ($type) { |
|||
case "float": |
|||
return (substr($value, -2) === ".0") ? "'".substr($value, 0, strlen($value) - 2)."'" : "'$value'"; |
|||
case "string": |
|||
if (preg_match("<^char\((\d+)\)$>", $value, $match)) { |
|||
return "'".\IntlChar::chr((int) $match[1])."'"; |
|||
} |
|||
return $value; |
|||
default: |
|||
return $value; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
<?php |
|||
/** @license MIT |
|||
* Copyright 2017 J. King, Dustin Wilson et al. |
|||
* See LICENSE and AUTHORS files for details */ |
|||
|
|||
declare(strict_types=1); |
|||
namespace JKingWeb\Arsse\TestCase\Db\MySQL; |
|||
|
|||
/** |
|||
* @group slow |
|||
* @covers \JKingWeb\Arsse\Db\MySQL\Driver<extended> */ |
|||
class TestUpdate extends \JKingWeb\Arsse\TestCase\Db\BaseUpdate { |
|||
use \JKingWeb\Arsse\TestCase\DatabaseDrivers\MySQL; |
|||
|
|||
protected static $minimal1 = "CREATE TABLE arsse_meta(`key` varchar(255) primary key, value text); INSERT INTO arsse_meta(`key`,value) values('schema_version','1');"; |
|||
protected static $minimal2 = "UPDATE arsse_meta set value = '2' where `key` = 'schema_version';"; |
|||
} |
Loading…
Reference in new issue