1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Unit tests for IN() clause generator

This commit is contained in:
J. King 2019-09-11 15:25:26 -04:00
parent 3aac583c00
commit d0f780d4e6
9 changed files with 66 additions and 7 deletions

View file

@ -10,7 +10,7 @@ use JKingWeb\Arsse\Test\Database;
use JKingWeb\Arsse\Arsse; use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\User; use JKingWeb\Arsse\User;
abstract class Base extends \JKingWeb\Arsse\Test\AbstractTest { abstract class AbstractTest extends \JKingWeb\Arsse\Test\AbstractTest {
use SeriesMiscellany; use SeriesMiscellany;
use SeriesMeta; use SeriesMeta;
use SeriesUser; use SeriesUser;

View file

@ -0,0 +1,58 @@
<?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\Database;
use JKingWeb\Arsse\Database;
/** @covers \JKingWeb\Arsse\Database */
class TestDatabase extends \JKingWeb\Arsse\Test\AbstractTest {
static $db = null;
public static function setUpBeforeClass() {
self::clearData();
self::setConf();
self::$db = \Phake::makeVisible(\Phake::partialMock(Database::class));
}
public static function tearDownAfterClass() {
self::$db = null;
self::clearData();
}
/** @dataProvider provideInClauses */
public function testGenerateInClause(string $clause, array $values, array $inV, string $inT) {
$types = array_fill(0, sizeof($values), $inT);
$exp = [$clause, $types, $values];
$this->assertSame($exp, self::$db->generateIn($inV, $inT));
}
public function provideInClauses() {
$l = Database::LIMIT_SET_SIZE + 1;
$strings = array_fill(0, $l, "");
$ints = range(1, $l);
$longString = str_repeat("0", Database::LIMIT_SET_STRING_LENGTH + 1);
$params = implode(",", array_fill(0, $l, "?"));
$intList = implode(",", $ints);
$stringList = implode(",", array_fill(0, $l, "''"));
return [
["null", [], [], "str"],
["?", [1], [1], "int"],
["?", ["1"], ["1"], "int"],
["?,?", [null, null], [null, null], "str"],
["null", [], array_fill(0, $l, null), "str"],
["$intList", [], $ints, "int"],
["$intList,".($l+1), [], array_merge($ints, [$l+1]), "int"],
["$intList,0", [], array_merge($ints, ["OOK"]), "int"],
["$intList", [], array_merge($ints, [null]), "int"],
["$stringList,''", [], array_merge($strings, [""]), "str"],
["$stringList", [], array_merge($strings, [null]), "str"],
["$stringList,?", [$longString], array_merge($strings, [$longString]), "str"],
["$stringList,'A''s'", [], array_merge($strings, ["A's"]), "str"],
["$params", $ints, $ints, "bool"],
];
}
}

View file

@ -12,7 +12,7 @@ namespace JKingWeb\Arsse\TestCase\Db\MySQL;
* @covers \JKingWeb\Arsse\Database<extended> * @covers \JKingWeb\Arsse\Database<extended>
* @covers \JKingWeb\Arsse\Misc\Query<extended> * @covers \JKingWeb\Arsse\Misc\Query<extended>
*/ */
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base { class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\AbstractTest {
use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQL; use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQL;
protected function nextID(string $table): int { protected function nextID(string $table): int {

View file

@ -13,7 +13,7 @@ namespace JKingWeb\Arsse\TestCase\Db\MySQLPDO;
* @covers \JKingWeb\Arsse\Database<extended> * @covers \JKingWeb\Arsse\Database<extended>
* @covers \JKingWeb\Arsse\Misc\Query<extended> * @covers \JKingWeb\Arsse\Misc\Query<extended>
*/ */
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base { class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\AbstractTest {
use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQLPDO; use \JKingWeb\Arsse\Test\DatabaseDrivers\MySQLPDO;
protected function nextID(string $table): int { protected function nextID(string $table): int {

View file

@ -12,7 +12,7 @@ namespace JKingWeb\Arsse\TestCase\Db\PostgreSQL;
* @covers \JKingWeb\Arsse\Database<extended> * @covers \JKingWeb\Arsse\Database<extended>
* @covers \JKingWeb\Arsse\Misc\Query<extended> * @covers \JKingWeb\Arsse\Misc\Query<extended>
*/ */
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base { class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\AbstractTest {
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQL; use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQL;
protected function nextID(string $table): int { protected function nextID(string $table): int {

View file

@ -13,7 +13,7 @@ namespace JKingWeb\Arsse\TestCase\Db\PostgreSQLPDO;
* @covers \JKingWeb\Arsse\Database<extended> * @covers \JKingWeb\Arsse\Database<extended>
* @covers \JKingWeb\Arsse\Misc\Query<extended> * @covers \JKingWeb\Arsse\Misc\Query<extended>
*/ */
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base { class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\AbstractTest {
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQLPDO; use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQLPDO;
protected function nextID(string $table): int { protected function nextID(string $table): int {

View file

@ -11,7 +11,7 @@ namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
* @covers \JKingWeb\Arsse\Database<extended> * @covers \JKingWeb\Arsse\Database<extended>
* @covers \JKingWeb\Arsse\Misc\Query<extended> * @covers \JKingWeb\Arsse\Misc\Query<extended>
*/ */
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base { class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\AbstractTest {
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3; use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3;
protected function nextID(string $table): int { protected function nextID(string $table): int {

View file

@ -10,7 +10,7 @@ namespace JKingWeb\Arsse\TestCase\Db\SQLite3PDO;
* @covers \JKingWeb\Arsse\Database<extended> * @covers \JKingWeb\Arsse\Database<extended>
* @covers \JKingWeb\Arsse\Misc\Query<extended> * @covers \JKingWeb\Arsse\Misc\Query<extended>
*/ */
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base { class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\AbstractTest {
use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3PDO; use \JKingWeb\Arsse\Test\DatabaseDrivers\SQLite3PDO;
protected function nextID(string $table): int { protected function nextID(string $table): int {

View file

@ -98,6 +98,7 @@
<file>cases/Db/MySQLPDO/TestUpdate.php</file> <file>cases/Db/MySQLPDO/TestUpdate.php</file>
</testsuite> </testsuite>
<testsuite name="Database functions"> <testsuite name="Database functions">
<file>cases/Database/TestDatabase.php</file>
<file>cases/Db/SQLite3/TestDatabase.php</file> <file>cases/Db/SQLite3/TestDatabase.php</file>
<file>cases/Db/SQLite3PDO/TestDatabase.php</file> <file>cases/Db/SQLite3PDO/TestDatabase.php</file>
<file>cases/Db/PostgreSQL/TestDatabase.php</file> <file>cases/Db/PostgreSQL/TestDatabase.php</file>