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

PDO tests and fixes; improves #72

This commit is contained in:
J. King 2017-12-19 19:08:08 -05:00
parent 4b46d654bb
commit 4bada691e9
18 changed files with 212 additions and 12 deletions

View file

@ -45,7 +45,7 @@ class RoboFile extends \Robo\Tasks {
* See help for the "test" task for more details.
*/
public function testQuick(array $args): Result {
return $this->test(array_merge(["--exclude-group","slow"], $args));
return $this->test(array_merge(["--exclude-group", "slow,optional"], $args));
}
/** Produces a code coverage report

View file

@ -415,7 +415,7 @@ class Database {
return $f;
}
protected function folderValidateMove(string $user, int $id = null, $parent = null, string $name = null) {
protected function folderValidateMove(string $user, $id = null, $parent = null, string $name = null) {
$errData = ["action" => $this->caller(), "field" => "parent", 'id' => $parent];
if (!$id) {
// the root cannot be moved
@ -467,7 +467,7 @@ class Database {
return $parent;
}
protected function folderValidateName($name, bool $checkDuplicates = false, int $parent = null): bool {
protected function folderValidateName($name, bool $checkDuplicates = false, $parent = null): bool {
$info = ValueInfo::str($name);
if ($info & (ValueInfo::NULL | ValueInfo::EMPTY)) {
throw new Db\ExceptionInput("missing", ["action" => $this->caller(), "field" => "name"]);
@ -572,7 +572,7 @@ class Database {
// add a suitable WHERE condition
$q->setWhere("folder in (select folder from folders)");
}
return $this->db->prepare($q->getQuery(), $q->getTypes())->run($q->getValues())->getValue();
return (int) $this->db->prepare($q->getQuery(), $q->getTypes())->run($q->getValues())->getValue();
}
public function subscriptionRemove(string $user, $id): bool {
@ -1102,7 +1102,7 @@ class Database {
$q = $this->articleQuery($user, $context);
$q->pushCTE("selected_articles");
$q->setBody("SELECT count(*) from selected_articles");
return $this->db->prepare($q->getQuery(), $q->getTypes())->run($q->getValues())->getValue();
return (int) $this->db->prepare($q->getQuery(), $q->getTypes())->run($q->getValues())->getValue();
}
}

View file

@ -0,0 +1,16 @@
<?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;
/**
* @covers \JKingWeb\Arsse\Database<extended>
* @group optional */
class TestDatabaseArticleSQLite3PDO extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3PDO;
use Test\Database\SeriesArticle;
}

View file

@ -0,0 +1,16 @@
<?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;
/**
* @covers \JKingWeb\Arsse\Database<extended>
* @group optional */
class TestDatabaseCleanupSQLite3PDO extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3PDO;
use Test\Database\SeriesCleanup;
}

View file

@ -0,0 +1,16 @@
<?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;
/**
* @covers \JKingWeb\Arsse\Database<extended>
* @group optional */
class TestDatabaseFeedSQLite3PDO extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3PDO;
use Test\Database\SeriesFeed;
}

View file

@ -0,0 +1,16 @@
<?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;
/**
* @covers \JKingWeb\Arsse\Database<extended>
* @group optional */
class TestDatabaseFolderSQLite3PDO extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3PDO;
use Test\Database\SeriesFolder;
}

View file

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace JKingWeb\Arsse;
/**
* @covers \JKingWeb\Arsse\Database<extended>
* @group optional */
class TestDatabaseLabelSQLite3PDO extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3PDO;
use Test\Database\SeriesLabel;
}

View file

@ -0,0 +1,16 @@
<?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;
/**
* @covers \JKingWeb\Arsse\Database<extended>
* @group optional */
class TestDatabaseMetaSQLite3PDO extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3PDO;
use Test\Database\SeriesMeta;
}

View file

@ -0,0 +1,16 @@
<?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;
/**
* @covers \JKingWeb\Arsse\Database<extended>
* @group optional */
class TestDatabaseMiscellanySQLite3PDO extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3PDO;
use Test\Database\SeriesMiscellany;
}

View file

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace JKingWeb\Arsse;
/**
* @covers \JKingWeb\Arsse\Database<extended>
* @group optional */
class TestDatabaseSessionSQLite3PDO extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3PDO;
use Test\Database\SeriesSession;
}

View file

@ -0,0 +1,16 @@
<?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;
/**
* @covers \JKingWeb\Arsse\Database<extended>
* @group optional */
class TestDatabaseSubscriptionSQLite3PDO extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3PDO;
use Test\Database\SeriesSubscription;
}

View file

@ -0,0 +1,16 @@
<?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;
/**
* @covers \JKingWeb\Arsse\Database<extended>
* @group optional */
class TestDatabaseUserSQLite3PDO extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3PDO;
use Test\Database\SeriesUser;
}

View file

@ -32,6 +32,8 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
public function approximateTime($exp, $act) {
if (is_null($act)) {
return null;
} elseif (is_null($exp)) {
return $act;
}
$target = Date::normalize($exp)->getTimeStamp();
$value = Date::normalize($act)->getTimeStamp();

View file

@ -0,0 +1,24 @@
<?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\Test\Database;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Db\SQLite3\PDODriver;
trait DriverSQLite3PDO {
public function setUpDriver() {
if (!PDODriver::requirementsMet()) {
$this->markTestSkipped("PDO-SQLite extension not loaded");
}
Arsse::$conf->dbSQLite3File = ":memory:";
$this->drv = new PDODriver();
}
public function nextID(string $table): int {
return (int) $this->drv->query("SELECT (case when max(id) then max(id) else 0 end)+1 from $table")->getValue();
}
}

View file

@ -888,8 +888,8 @@ trait SeriesArticle {
public function testFetchStarredCounts() {
$exp1 = ['total' => 2, 'unread' => 1, 'read' => 1];
$exp2 = ['total' => 0, 'unread' => 0, 'read' => 0];
$this->assertSame($exp1, Arsse::$db->articleStarred("john.doe@example.com"));
$this->assertSame($exp2, Arsse::$db->articleStarred("jane.doe@example.com"));
$this->assertEquals($exp1, Arsse::$db->articleStarred("john.doe@example.com"));
$this->assertEquals($exp2, Arsse::$db->articleStarred("jane.doe@example.com"));
}
public function testFetchStarredCountsWithoutAuthority() {

View file

@ -256,9 +256,9 @@ trait SeriesFeed {
}
public function testListStaleFeeds() {
$this->assertSame([1,3,4], Arsse::$db->feedListStale());
$this->assertEquals([1,3,4], Arsse::$db->feedListStale());
Arsse::$db->feedUpdate(3);
Arsse::$db->feedUpdate(4);
$this->assertSame([1], Arsse::$db->feedListStale());
$this->assertEquals([1], Arsse::$db->feedListStale());
}
}

View file

@ -10,6 +10,7 @@ use JKingWeb\Arsse\User\Driver as UserDriver;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\User;
use JKingWeb\Arsse\Misc\ValueInfo;
use JKingWeb\Arsse\Test\Database;
use JKingWeb\Arsse\Db\Result;
use Phake;
@ -90,8 +91,19 @@ trait Setup {
$row = array_combine($cols, $row);
foreach($data as $index => $test) {
foreach ($test as $col => $value) {
if ($types[$col]=="datetime") {
$test[$col] = $this->approximateTime($row[$col], $value);
switch ($types[$col]) {
case "datetime":
$test[$col] = $this->approximateTime($row[$col], $value);
break;
case "int":
$test[$col] = ValueInfo::normalize($value, ValueInfo::T_INT | ValueInfo::M_DROP | valueInfo::M_NULL);
break;
case "float":
$test[$col] = ValueInfo::normalize($value, ValueInfo::T_FLOAT | ValueInfo::M_DROP | valueInfo::M_NULL);
break;
case "bool":
$test[$col] = (int) ValueInfo::normalize($value, ValueInfo::T_BOOL | ValueInfo::M_DROP | valueInfo::M_NULL);
break;
}
}
if($row===$test) {

View file

@ -58,7 +58,7 @@
<file>cases/Db/SQLite3PDO/TestDbDriverSQLite3PDO.php</file>
<file>cases/Db/SQLite3PDO/TestDbUpdateSQLite3PDO.php</file>
</testsuite>
<testsuite name="Database functions">
<testsuite name="Database functions">
<file>cases/Db/SQLite3/Database/TestDatabaseMiscellanySQLite3.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseMetaSQLite3.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseUserSQLite3.php</file>
@ -69,6 +69,16 @@
<file>cases/Db/SQLite3/Database/TestDatabaseArticleSQLite3.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseLabelSQLite3.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseCleanupSQLite3.php</file>
<file>cases/Db/SQLite3PDO/Database/TestDatabaseMiscellanySQLite3PDO.php</file>
<file>cases/Db/SQLite3PDO/Database/TestDatabaseUserSQLite3PDO.php</file>
<file>cases/Db/SQLite3PDO/Database/TestDatabaseSessionSQLite3PDO.php</file>
<file>cases/Db/SQLite3PDO/Database/TestDatabaseFolderSQLite3PDO.php</file>
<file>cases/Db/SQLite3PDO/Database/TestDatabaseFeedSQLite3PDO.php</file>
<file>cases/Db/SQLite3PDO/Database/TestDatabaseSubscriptionSQLite3PDO.php</file>
<file>cases/Db/SQLite3PDO/Database/TestDatabaseArticleSQLite3PDO.php</file>
<file>cases/Db/SQLite3PDO/Database/TestDatabaseLabelSQLite3PDO.php</file>
<file>cases/Db/SQLite3PDO/Database/TestDatabaseCleanupSQLite3PDO.php</file>
</testsuite>
<testsuite name="Controllers">
<testsuite name="NCNv1">