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

Reorganize PDO tests into namespaces

This commit is contained in:
J. King 2017-12-22 11:41:54 -05:00
parent 4bada691e9
commit 095fe10aec
52 changed files with 425 additions and 341 deletions

View file

@ -10,6 +10,7 @@ const BASE = __DIR__.DIRECTORY_SEPARATOR;
$paths = [
__FILE__,
BASE."arsse.php",
BASE."RoboFile.php",
BASE."lib",
BASE."tests",
];

View file

@ -11,15 +11,15 @@ class RoboFile extends \Robo\Tasks {
const BASE = __DIR__.\DIRECTORY_SEPARATOR;
const BASE_TEST = self::BASE."tests".\DIRECTORY_SEPARATOR;
/**
* Runs the full test suite
*
* Arguments passed to the task are passed on to PHPUnit. Thus one may, for
/**
* Runs the full test suite
*
* Arguments passed to the task are passed on to PHPUnit. Thus one may, for
* example, run the following command and get the expected results:
*
* ./robo test --testsuite TTRSS --exclude-group slow --testdox
*
* Please see the PHPUnit documentation for available options.
*
* ./robo test --testsuite TTRSS --exclude-group slow --testdox
*
* Please see the PHPUnit documentation for available options.
*/
public function test(array $args): Result {
// start the built-in PHP server, which is required for some of the tests
@ -30,32 +30,32 @@ class RoboFile extends \Robo\Tasks {
return $this->taskExec("php")->arg($execpath)->option("-c", $confpath)->args($args)->run();
}
/**
* Runs the full test suite
*
* This is an alias of the "test" task.
/**
* Runs the full test suite
*
* This is an alias of the "test" task.
*/
public function testFull(array $args): Result {
return $this->test($args);
}
/**
* Runs a quick subset of the test suite
*
* See help for the "test" task for more details.
/**
* Runs a quick subset of the test suite
*
* See help for the "test" task for more details.
*/
public function testQuick(array $args): Result {
return $this->test(array_merge(["--exclude-group", "slow,optional"], $args));
}
/** Produces a code coverage report
*
/** Produces a code coverage report
*
* By default this task produces an HTML-format coverage report in
* arsse/tests/coverage/. Additional reports may be produced by passing
* arguments to this task as one would to PHPUnit.
*
*
* Robo first tries to use phpdbg and will fall back to Xdebug if available.
* Because Xdebug slows down non-coverage tasks, however, phpdbg is highly
* Because Xdebug slows down non-coverage tasks, however, phpdbg is highly
* recommanded is debugging facilities are not otherwise needed.
*/
public function coverage(array $args): Result {
@ -79,14 +79,14 @@ class RoboFile extends \Robo\Tasks {
}
}
/** Packages a given commit of the software into a release tarball
*
/** Packages a given commit of the software into a release tarball
*
* The version to package may be any Git tree-ish identifier: a tag, a branch,
* or any commit hash. If none is provided on the command line, Robo will prompt
* for a commit to package; the default is "head".
*
*
* Note that while it is possible to re-package old versions, the resultant tarball
* may not be equivalent due to subsequent changes in the exclude list, or because
* may not be equivalent due to subsequent changes in the exclude list, or because
* of new tooling.
*/
public function package(string $version = null): Result {
@ -128,4 +128,13 @@ class RoboFile extends \Robo\Tasks {
$this->_exec("git worktree prune");
return $out;
}
}
public function clean($opts = ['demo|d' => false]): Result {
$t = $this->taskExec(realpath(self::BASE."vendor/bin/php-cs-fixer"));
$t->arg("fix");
if ($opts['demo']) {
$t->args("--dry-run", "--diff")->option("--diff-format", "udiff");
}
return $t->run();
}
}

6
robo
View file

@ -3,4 +3,8 @@ base=`dirname "$0"`
roboCommand="$1"
shift
"$base/vendor/bin/robo" "$roboCommand" -- $*
if [ "$1" == "clean" ]; then
"$base/vendor/bin/robo" "$roboCommand" $*
else
"$base/vendor/bin/robo" "$roboCommand" -- $*
fi

View file

@ -14,4 +14,8 @@ if "%~1" neq "" (
)
if defined args set args=%args:~1%
call "%base%vendor\bin\robo" "%roboCommand%" -- %args%
if "%1"=="clean" (
call "%base%vendor\bin\robo" "%roboCommand%" %args%
) else (
call "%base%vendor\bin\robo" "%roboCommand%" -- %args%
)

View file

@ -4,12 +4,13 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Conf;
use JKingWeb\Arsse\Conf;
use org\bovigo\vfs\vfsStream;
/** @covers \JKingWeb\Arsse\Conf */
class TestConf extends Test\AbstractTest {
class TestConf extends \JKingWeb\Arsse\Test\AbstractTest {
public static $vfs;
public static $path;

View file

@ -0,0 +1,14 @@
<?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\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestArticle extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesArticle;
}

View file

@ -0,0 +1,14 @@
<?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\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestCleanup extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesCleanup;
}

View file

@ -1,14 +0,0 @@
<?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> */
class TestDatabaseArticleSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesArticle;
}

View file

@ -1,14 +0,0 @@
<?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> */
class TestDatabaseCleanupSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesCleanup;
}

View file

@ -1,14 +0,0 @@
<?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> */
class TestDatabaseFeedSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesFeed;
}

View file

@ -1,14 +0,0 @@
<?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> */
class TestDatabaseFolderSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesFolder;
}

View file

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

View file

@ -1,14 +0,0 @@
<?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> */
class TestDatabaseMetaSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesMeta;
}

View file

@ -1,14 +0,0 @@
<?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> */
class TestDatabaseMiscellanySQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesMiscellany;
}

View file

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

View file

@ -1,14 +0,0 @@
<?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> */
class TestDatabaseSubscriptionSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesSubscription;
}

View file

@ -1,14 +0,0 @@
<?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> */
class TestDatabaseUserSQLite3 extends Test\AbstractTest {
use Test\Database\Setup;
use Test\Database\DriverSQLite3;
use Test\Database\SeriesUser;
}

View file

@ -0,0 +1,14 @@
<?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\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestFeed extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesFeed;
}

View file

@ -0,0 +1,14 @@
<?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\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestFolder extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesFolder;
}

View file

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\Db\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestLabel extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesLabel;
}

View file

@ -0,0 +1,14 @@
<?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\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestMeta extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesMeta;
}

View file

@ -0,0 +1,14 @@
<?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\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestMiscellany extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesMiscellany;
}

View file

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\Db\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestSession extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesSession;
}

View file

@ -0,0 +1,14 @@
<?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\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestSubscription extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesSubscription;
}

View file

@ -0,0 +1,14 @@
<?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\SQLite3\Database;
/** @covers \JKingWeb\Arsse\Database<extended> */
class TestUser extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Database\Setup;
use \JKingWeb\Arsse\Test\Database\DriverSQLite3;
use \JKingWeb\Arsse\Test\Database\SeriesUser;
}

View file

@ -4,9 +4,10 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\Db\SQLite3\Driver;
use org\bovigo\vfs\vfsStream;
use Phake;
@ -14,7 +15,7 @@ use Phake;
/**
* @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended>
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
class TestDbDriverCreationSQLite3 extends Test\AbstractTest {
class TestCreation extends \JKingWeb\Arsse\Test\AbstractTest {
protected $data;
protected $drv;
protected $ch;

View file

@ -4,12 +4,19 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Db\SQLite3\Driver;
use JKingWeb\Arsse\Db\SQLite3\Result;
use JKingWeb\Arsse\Db\SQLite3\Statement;
/**
* @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended>
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
class TestDbDriverSQLite3 extends Test\AbstractTest {
class TestDriver extends \JKingWeb\Arsse\Test\AbstractTest {
protected $data;
protected $drv;
protected $ch;
@ -21,10 +28,10 @@ class TestDbDriverSQLite3 extends Test\AbstractTest {
$this->clearData();
$conf = new Conf();
Arsse::$conf = $conf;
$conf->dbDriver = Db\SQLite3\Driver::class;
$conf->dbDriver = Driver::class;
$conf->dbSQLite3Timeout = 0;
$conf->dbSQLite3File = tempnam(sys_get_temp_dir(), 'ook');
$this->drv = new Db\SQLite3\Driver();
$this->drv = new Driver();
$this->ch = new \SQLite3(Arsse::$conf->dbSQLite3File);
$this->ch->enableExceptions(true);
}
@ -80,7 +87,7 @@ class TestDbDriverSQLite3 extends Test\AbstractTest {
}
public function testMakeAValidQuery() {
$this->assertInstanceOf(Db\Result::class, $this->drv->query("SELECT 1"));
$this->assertInstanceOf(Result::class, $this->drv->query("SELECT 1"));
}
public function testMakeAnInvalidQuery() {
@ -108,7 +115,7 @@ class TestDbDriverSQLite3 extends Test\AbstractTest {
public function testPrepareAValidQuery() {
$s = $this->drv->prepare("SELECT ?, ?", "int", "int");
$this->assertInstanceOf(Db\Statement::class, $s);
$this->assertInstanceOf(Statement::class, $s);
}
public function testPrepareAnInvalidQuery() {

View file

@ -4,10 +4,12 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
use JKingWeb\Arsse\Db\SQLite3\Result;
/** @covers \JKingWeb\Arsse\Db\SQLite3\Result<extended> */
class TestDbResultSQLite3 extends Test\AbstractTest {
class TestResult extends \JKingWeb\Arsse\Test\AbstractTest {
protected $c;
public function setUp() {
@ -28,7 +30,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
public function testConstructResult() {
$set = $this->c->query("SELECT 1");
$this->assertInstanceOf(Db\Result::class, new Db\SQLite3\Result($set));
$this->assertInstanceOf(Result::class, new Result($set));
}
public function testGetChangeCountAndLastInsertId() {
@ -36,7 +38,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
$set = $this->c->query("INSERT INTO test(col) values(1)");
$rows = $this->c->changes();
$id = $this->c->lastInsertRowID();
$r = new Db\SQLite3\Result($set, [$rows,$id]);
$r = new Result($set, [$rows,$id]);
$this->assertEquals($rows, $r->changes());
$this->assertEquals($id, $r->lastId());
}
@ -44,7 +46,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
public function testIterateOverResults() {
$set = $this->c->query("SELECT 1 as col union select 2 as col union select 3 as col");
$rows = [];
foreach (new Db\SQLite3\Result($set) as $index => $row) {
foreach (new Result($set) as $index => $row) {
$rows[$index] = $row['col'];
}
$this->assertEquals([0 => 1, 1 => 2, 2 => 3], $rows);
@ -53,7 +55,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
public function testIterateOverResultsTwice() {
$set = $this->c->query("SELECT 1 as col union select 2 as col union select 3 as col");
$rows = [];
$test = new Db\SQLite3\Result($set);
$test = new Result($set);
foreach ($test as $row) {
$rows[] = $row['col'];
}
@ -66,7 +68,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
public function testGetSingleValues() {
$set = $this->c->query("SELECT 1867 as year union select 1970 as year union select 2112 as year");
$test = new Db\SQLite3\Result($set);
$test = new Result($set);
$this->assertEquals(1867, $test->getValue());
$this->assertEquals(1970, $test->getValue());
$this->assertEquals(2112, $test->getValue());
@ -75,7 +77,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
public function testGetFirstValuesOnly() {
$set = $this->c->query("SELECT 1867 as year, 19 as century union select 1970 as year, 20 as century union select 2112 as year, 22 as century");
$test = new Db\SQLite3\Result($set);
$test = new Result($set);
$this->assertEquals(1867, $test->getValue());
$this->assertEquals(1970, $test->getValue());
$this->assertEquals(2112, $test->getValue());
@ -88,7 +90,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
['album' => '2112', 'track' => '2112'],
['album' => 'Clockwork Angels', 'track' => 'The Wreckers'],
];
$test = new Db\SQLite3\Result($set);
$test = new Result($set);
$this->assertEquals($rows[0], $test->getRow());
$this->assertEquals($rows[1], $test->getRow());
$this->assertSame(null, $test->getRow());
@ -100,7 +102,7 @@ class TestDbResultSQLite3 extends Test\AbstractTest {
['album' => '2112', 'track' => '2112'],
['album' => 'Clockwork Angels', 'track' => 'The Wreckers'],
];
$test = new Db\SQLite3\Result($set);
$test = new Result($set);
$this->assertEquals($rows, $test->getAll());
}
}

View file

@ -4,18 +4,18 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
use JKingWeb\Arsse\Db\Statement;
/**
* @covers \JKingWeb\Arsse\Db\SQLite3\Statement<extended>
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
class TestDbStatementSQLite3 extends Test\AbstractTest {
use Test\Db\BindingTests;
class TestStatement extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Db\BindingTests;
protected $c;
protected static $imp = Db\SQLite3\Statement::class;
protected static $imp = \JKingWeb\Arsse\Db\SQLite3\Statement::class;
public function setUp() {
$this->clearData();
@ -48,7 +48,7 @@ class TestDbStatementSQLite3 extends Test\AbstractTest {
public function testConstructStatement() {
$nativeStatement = $this->c->prepare("SELECT ? as value");
$this->assertInstanceOf(Statement::class, new Db\SQLite3\Statement($this->c, $nativeStatement));
$this->assertInstanceOf(Statement::class, new \JKingWeb\Arsse\Db\SQLite3\Statement($this->c, $nativeStatement));
}
public function testBindMissingValue() {

View file

@ -4,14 +4,19 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Db\SQLite3;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Db\Exception;
use JKingWeb\Arsse\Db\SQLite3\Driver;
use org\bovigo\vfs\vfsStream;
/**
* @covers \JKingWeb\Arsse\Db\SQLite3\Driver<extended>
* @covers \JKingWeb\Arsse\Db\SQLite3\ExceptionBuilder */
class TestDbUpdateSQLite3 extends Test\AbstractTest {
class TestUpdate extends \JKingWeb\Arsse\Test\AbstractTest {
protected $data;
protected $drv;
protected $vfs;
@ -29,12 +34,12 @@ class TestDbUpdateSQLite3 extends Test\AbstractTest {
if (!$conf) {
$conf = new Conf();
}
$conf->dbDriver = Db\SQLite3\Driver::class;
$conf->dbDriver = Driver::class;
$conf->dbSQLite3File = ":memory:";
Arsse::$conf = $conf;
$this->base = $this->vfs->url();
$this->path = $this->base."/SQLite3/";
$this->drv = new Db\SQLite3\Driver();
$this->drv = new Driver();
}
public function tearDown() {

View file

@ -1,18 +1,19 @@
<?php
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Db;
use JKingWeb\Arsse\Db\ResultAggregate;
use JKingWeb\Arsse\Test\Result;
/** @covers \JKingWeb\Arsse\Db\ResultAggregate<extended> */
class TestResultAggregate extends Test\AbstractTest {
class TestResultAggregate extends \JKingWeb\Arsse\Test\AbstractTest {
public function testGetChangeCountAndLastInsertId() {
$in = [
new Result([], 3, 4),
new Result([], 27, 10),
new Result([], 12, 2112),
];
$r = new Db\ResultAggregate(...$in);
$r = new ResultAggregate(...$in);
$this->assertEquals(42, $r->changes());
$this->assertEquals(2112, $r->lastId());
}
@ -24,7 +25,7 @@ class TestResultAggregate extends Test\AbstractTest {
new Result([['col' => 3]]),
];
$rows = [];
foreach (new Db\ResultAggregate(...$in) as $index => $row) {
foreach (new ResultAggregate(...$in) as $index => $row) {
$rows[$index] = $row['col'];
}
$this->assertEquals([0 => 1, 1 => 2, 2 => 3], $rows);
@ -37,7 +38,7 @@ class TestResultAggregate extends Test\AbstractTest {
new Result([['col' => 3]]),
];
$rows = [];
$test = new Db\ResultAggregate(...$in);
$test = new ResultAggregate(...$in);
foreach ($test as $row) {
$rows[] = $row['col'];
}
@ -49,7 +50,7 @@ class TestResultAggregate extends Test\AbstractTest {
}
public function testGetSingleValues() {
$test = new Db\ResultAggregate(...[
$test = new ResultAggregate(...[
new Result([['year' => 1867]]),
new Result([['year' => 1970]]),
new Result([['year' => 2112]]),
@ -61,7 +62,7 @@ class TestResultAggregate extends Test\AbstractTest {
}
public function testGetFirstValuesOnly() {
$test = new Db\ResultAggregate(...[
$test = new ResultAggregate(...[
new Result([['year' => 1867, 'century' => 19]]),
new Result([['year' => 1970, 'century' => 20]]),
new Result([['year' => 2112, 'century' => 22]]),
@ -73,7 +74,7 @@ class TestResultAggregate extends Test\AbstractTest {
}
public function testGetRows() {
$test = new Db\ResultAggregate(...[
$test = new ResultAggregate(...[
new Result([['album' => '2112', 'track' => '2112']]),
new Result([['album' => 'Clockwork Angels', 'track' => 'The Wreckers']]),
]);
@ -87,7 +88,7 @@ class TestResultAggregate extends Test\AbstractTest {
}
public function testGetAllRows() {
$test = new Db\ResultAggregate(...[
$test = new ResultAggregate(...[
new Result([['album' => '2112', 'track' => '2112']]),
new Result([['album' => 'Clockwork Angels', 'track' => 'The Wreckers']]),
]);

View file

@ -1,35 +1,37 @@
<?php
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Db;
use JKingWeb\Arsse\Db\ResultEmpty;
/** @covers \JKingWeb\Arsse\Db\ResultEmpty<extended> */
class TestResultEmpty extends Test\AbstractTest {
class TestResultEmpty extends \JKingWeb\Arsse\Test\AbstractTest {
public function testGetChangeCountAndLastInsertId() {
$r = new Db\ResultEmpty;
$r = new ResultEmpty;
$this->assertEquals(0, $r->changes());
$this->assertEquals(0, $r->lastId());
}
public function testIterateOverResults() {
$rows = [];
foreach (new Db\ResultEmpty as $index => $row) {
foreach (new ResultEmpty as $index => $row) {
$rows[$index] = $row['col'];
}
$this->assertEquals([], $rows);
}
public function testGetSingleValues() {
$test = new Db\ResultEmpty;
$test = new ResultEmpty;
$this->assertSame(null, $test->getValue());
}
public function testGetRows() {
$test = new Db\ResultEmpty;
$test = new ResultEmpty;
$this->assertSame(null, $test->getRow());
}
public function testGetAllRows() {
$test = new Db\ResultEmpty;
$test = new ResultEmpty;
$rows = [];
$this->assertEquals($rows, $test->getAll());
}

View file

@ -4,19 +4,20 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Db;
use JKingWeb\Arsse\Db\Transaction;
use JKingWeb\Arsse\Db\Exception;
use Phake;
/**
* @covers \JKingWeb\Arsse\Db\Transaction */
class TestTransaction extends Test\AbstractTest {
class TestTransaction extends \JKingWeb\Arsse\Test\AbstractTest {
protected $drv;
public function setUp() {
$this->clearData();
$drv = Phake::mock(Db\SQLite3\Driver::class);
$drv = Phake::mock(\JKingWeb\Arsse\Db\SQLite3\Driver::class);
Phake::when($drv)->savepointRelease->thenReturn(true);
Phake::when($drv)->savepointUndo->thenReturn(true);
Phake::when($drv)->savepointCreate->thenReturn(1)->thenReturn(2);
@ -51,7 +52,7 @@ class TestTransaction extends Test\AbstractTest {
}
public function testIgnoreRollbackErrors() {
Phake::when($this->drv)->savepointUndo->thenThrow(new Db\Exception("savepointStale"));
Phake::when($this->drv)->savepointUndo->thenThrow(new Exception("savepointStale"));
$tr1 = new Transaction($this->drv);
$tr2 = new Transaction($this->drv);
unset($tr1, $tr2); // no exception should bubble up

View file

@ -4,12 +4,16 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Exception;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Lang;
use JKingWeb\Arsse\Exception;
use JKingWeb\Arsse\Lang\Exception as LangException;
use Phake;
/** @covers \JKingWeb\Arsse\AbstractException */
class TestException extends Test\AbstractTest {
class TestException extends \JKingWeb\Arsse\Test\AbstractTest {
public function setUp() {
$this->clearData(false);
// create a mock Lang object so as not to create a dependency loop
@ -43,7 +47,7 @@ class TestException extends Test\AbstractTest {
*/
public function testDerivedClass() {
$this->assertException("fileMissing", "Lang");
throw new Lang\Exception("fileMissing");
throw new LangException("fileMissing");
}
/**
@ -51,7 +55,7 @@ class TestException extends Test\AbstractTest {
*/
public function testDerivedClassWithMessageParameters() {
$this->assertException("fileMissing", "Lang");
throw new Lang\Exception("fileMissing", "en");
throw new LangException("fileMissing", "en");
}
/**
@ -67,6 +71,6 @@ class TestException extends Test\AbstractTest {
*/
public function testDerivedClassWithMissingMessage() {
$this->assertException("uncoded");
throw new Lang\Exception("testThisExceptionMessageDoesNotExist");
throw new LangException("testThisExceptionMessageDoesNotExist");
}
}

View file

@ -4,16 +4,21 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Feed;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\Feed;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Misc\Date;
use JKingWeb\Arsse\Test\Result;
use Phake;
/**
* @covers \JKingWeb\Arsse\Feed
* @covers \JKingWeb\Arsse\Feed\Exception
* @group slow */
class TestFeed extends Test\AbstractTest {
class TestFeed extends \JKingWeb\Arsse\Test\AbstractTest {
protected static $host = "http://localhost:8000/";
protected $base = "";
protected $latest = [
@ -329,7 +334,7 @@ class TestFeed extends Test\AbstractTest {
}
public function testMatchLatestArticles() {
Phake::when(Arsse::$db)->feedMatchLatest(1, $this->anything())->thenReturn(new Test\Result($this->latest));
Phake::when(Arsse::$db)->feedMatchLatest(1, $this->anything())->thenReturn(new Result($this->latest));
$f = new Feed(1, $this->base."Matching/1");
$this->assertCount(0, $f->newItems);
$this->assertCount(0, $f->changedItems);
@ -345,8 +350,8 @@ class TestFeed extends Test\AbstractTest {
}
public function testMatchHistoricalArticles() {
Phake::when(Arsse::$db)->feedMatchLatest(1, $this->anything())->thenReturn(new Test\Result($this->latest));
Phake::when(Arsse::$db)->feedMatchIds(1, $this->anything(), $this->anything(), $this->anything(), $this->anything())->thenReturn(new Test\Result($this->others));
Phake::when(Arsse::$db)->feedMatchLatest(1, $this->anything())->thenReturn(new Result($this->latest));
Phake::when(Arsse::$db)->feedMatchIds(1, $this->anything(), $this->anything(), $this->anything(), $this->anything())->thenReturn(new Result($this->others));
$f = new Feed(1, $this->base."Matching/5");
$this->assertCount(0, $f->newItems);
$this->assertCount(0, $f->changedItems);

View file

@ -4,14 +4,17 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Feed;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\Feed;
use Phake;
/**
* @covers \JKingWeb\Arsse\Feed
/**
* @covers \JKingWeb\Arsse\Feed
* @group slow */
class TestFeedFetching extends Test\AbstractTest {
class TestFetching extends \JKingWeb\Arsse\Test\AbstractTest {
protected static $host = "http://localhost:8000/";
protected $base = "";

View file

@ -4,13 +4,15 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Lang;
use JKingWeb\Arsse\Lang as TestClass;
use org\bovigo\vfs\vfsStream;
/** @covers \JKingWeb\Arsse\Lang */
class TestLang extends Test\AbstractTest {
use Test\Lang\Setup;
class TestBasic extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Lang\Setup;
public $files;
public $path;
@ -38,14 +40,14 @@ class TestLang extends Test\AbstractTest {
*/
public function testLoadInternalStrings() {
$this->assertEquals("", $this->l->set("", true));
$this->assertCount(sizeof(Lang::REQUIRED), $this->l->dump());
$this->assertCount(sizeof(TestClass::REQUIRED), $this->l->dump());
}
/**
* @depends testLoadInternalStrings
*/
public function testLoadDefaultLanguage() {
$this->assertEquals(Lang::DEFAULT, $this->l->set(Lang::DEFAULT, true));
$this->assertEquals(TestClass::DEFAULT, $this->l->set(TestClass::DEFAULT, true));
$str = $this->l->dump();
$this->assertArrayHasKey('Exception.JKingWeb/Arsse/Exception.uncoded', $str);
$this->assertArrayHasKey('Test.presentText', $str);
@ -55,7 +57,7 @@ class TestLang extends Test\AbstractTest {
* @depends testLoadDefaultLanguage
*/
public function testLoadSupplementaryLanguage() {
$this->l->set(Lang::DEFAULT, true);
$this->l->set(TestClass::DEFAULT, true);
$this->assertEquals("ja", $this->l->set("ja", true));
$str = $this->l->dump();
$this->assertArrayHasKey('Exception.JKingWeb/Arsse/Exception.uncoded', $str);

View file

@ -4,13 +4,14 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Lang;
use JKingWeb\Arsse\Lang as TestClass;
use org\bovigo\vfs\vfsStream;
/** @covers \JKingWeb\Arsse\Lang */
class TestLangErrors extends Test\AbstractTest {
use Test\Lang\Setup;
class TestErrors extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Lang\Setup;
public $files;
public $path;
@ -62,7 +63,7 @@ class TestLangErrors extends Test\AbstractTest {
}
public function testLoadMissingDefaultLanguage() {
unlink($this->path.Lang::DEFAULT.".php");
unlink($this->path.TestClass::DEFAULT.".php");
$this->assertException("defaultFileMissing", "Lang");
$this->l->set("fr", true);
}

View file

@ -4,20 +4,21 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Lang;
use JKingWeb\Arsse\Lang as TestClass;
use org\bovigo\vfs\vfsStream;
/** @covers \JKingWeb\Arsse\Lang */
class TestLangComplex extends Test\AbstractTest {
use Test\Lang\Setup;
class TestComplex extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\Lang\Setup;
public $files;
public $path;
public $l;
public function setUpSeries() {
$this->l->set(Lang::DEFAULT, true);
$this->l->set(TestClass::DEFAULT, true);
}
public function testLazyLoad() {
@ -68,7 +69,7 @@ class TestLangComplex extends Test\AbstractTest {
*/
public function testFetchAMessageWithSingleNumericParameter() {
$this->l->set("en_ca", true);
$this->assertEquals('Default language file "en" missing', $this->l->msg('Exception.JKingWeb/Arsse/Lang/Exception.defaultFileMissing', Lang::DEFAULT));
$this->assertEquals('Default language file "en" missing', $this->l->msg('Exception.JKingWeb/Arsse/Lang/Exception.defaultFileMissing', TestClass::DEFAULT));
}
/**

View file

@ -4,12 +4,12 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Misc;
use JKingWeb\Arsse\Misc\Context;
/** @covers \JKingWeb\Arsse\Misc\Context */
class TestContext extends Test\AbstractTest {
class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
public function testVerifyInitialState() {
$c = new Context;
foreach ((new \ReflectionObject($c))->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) {

View file

@ -4,13 +4,15 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Misc;
use JKingWeb\Arsse\ExceptionType;
use JKingWeb\Arsse\Misc\ValueInfo as I;
use JKingWeb\Arsse\Test\Misc\StrClass;
use JKingWeb\Arsse\Test\Result;
/** @covers \JKingWeb\Arsse\Misc\ValueInfo */
class TestValueInfo extends Test\AbstractTest {
class TestValueInfo extends \JKingWeb\Arsse\Test\AbstractTest {
public function setUp() {
$this->clearData();
}
@ -398,7 +400,7 @@ class TestValueInfo extends Test\AbstractTest {
[1e-6, [null,true], [true, false], [0, false], [1e-6, true], ["0.000001", true], [[1e-6], false]],
[[1,2,3], [null,true], [true, false], [0, false], [0.0, false], ["", false], [[1,2,3], true] ],
[['a'=>1,'b'=>2], [null,true], [true, false], [0, false], [0.0, false], ["", false], [['a'=>1,'b'=>2], true] ],
[new Test\Result([['a'=>1,'b'=>2]]), [null,true], [true, false], [0, false], [0.0, false], ["", false], [[['a'=>1,'b'=>2]], true] ],
[new Result([['a'=>1,'b'=>2]]), [null,true], [true, false], [0, false], [0.0, false], ["", false], [[['a'=>1,'b'=>2]], true] ],
];
$params = [
[I::T_MIXED, "Mixed" ],
@ -496,8 +498,8 @@ class TestValueInfo extends Test\AbstractTest {
}
// Array-mode tests
$tests = [
[I::T_INT | I::M_DROP, new Test\Result([1, 2, 2.2, 3]), [1,2,null,3] ],
[I::T_INT, new Test\Result([1, 2, 2.2, 3]), [1,2,2,3] ],
[I::T_INT | I::M_DROP, new Result([1, 2, 2.2, 3]), [1,2,null,3] ],
[I::T_INT, new Result([1, 2, 2.2, 3]), [1,2,2,3] ],
[I::T_STRING | I::M_STRICT, "Bare string", ["Bare string"]],
];
foreach ($tests as $index => $test) {

View file

@ -4,8 +4,13 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\REST\NextCloudNews;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\User;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Service;
use JKingWeb\Arsse\REST\Request;
use JKingWeb\Arsse\REST\Response;
use JKingWeb\Arsse\Test\Result;
@ -13,10 +18,11 @@ use JKingWeb\Arsse\Misc\Date;
use JKingWeb\Arsse\Misc\Context;
use JKingWeb\Arsse\Db\ExceptionInput;
use JKingWeb\Arsse\Db\Transaction;
use JKingWeb\Arsse\REST\NextCloudNews\V1_2;
use Phake;
/** @covers \JKingWeb\Arsse\REST\NextCloudNews\V1_2<extended> */
class TestNCNV1_2 extends Test\AbstractTest {
class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
protected $h;
protected $feeds = [ // expected sample output of a feed list from the database, and the resultant expected transformation by the REST handler
'db' => [
@ -304,7 +310,7 @@ class TestNCNV1_2 extends Test\AbstractTest {
// create a mock database interface
Arsse::$db = Phake::mock(Database::class);
Phake::when(Arsse::$db)->begin->thenReturn(Phake::mock(Transaction::class));
$this->h = new REST\NextCloudNews\V1_2();
$this->h = new V1_2();
}
public function tearDown() {
@ -318,7 +324,7 @@ class TestNCNV1_2 extends Test\AbstractTest {
public function testSendAuthenticationChallenge() {
Phake::when(Arsse::$user)->authHTTP->thenReturn(false);
$exp = new Response(401, "", "", ['WWW-Authenticate: Basic realm="'.REST\NextCloudNews\V1_2::REALM.'"']);
$exp = new Response(401, "", "", ['WWW-Authenticate: Basic realm="'.V1_2::REALM.'"']);
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/")));
}
@ -496,7 +502,7 @@ class TestNCNV1_2 extends Test\AbstractTest {
public function testRetrieveServerVersion() {
$exp = new Response(200, [
'version' => REST\NextCloudNews\V1_2::VERSION,
'version' => V1_2::VERSION,
'arsse_version' => Arsse::VERSION,
]);
$this->assertResponse($exp, $this->h->dispatch(new Request("GET", "/version")));
@ -867,7 +873,7 @@ class TestNCNV1_2 extends Test\AbstractTest {
Phake::when(Arsse::$db)->metaGet("service_last_checkin")->thenReturn(Date::transform($valid, "sql"))->thenReturn(Date::transform($invalid, "sql"));
Phake::when(Arsse::$db)->driverCharsetAcceptable->thenReturn(true)->thenReturn(false);
$arr1 = $arr2 = [
'version' => REST\NextCloudNews\V1_2::VERSION,
'version' => V1_2::VERSION,
'arsse_version' => Arsse::VERSION,
'warnings' => [
'improperlyConfiguredCron' => false,

View file

@ -4,20 +4,21 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\REST\NextCloudNews;
use JKingWeb\Arsse\REST\NextCloudNews\Versions;
use JKingWeb\Arsse\REST\Request;
use JKingWeb\Arsse\REST\Response;
/** @covers \JKingWeb\Arsse\REST\NextCloudNews\Versions */
class TestNCNVersionDiscovery extends Test\AbstractTest {
class TestVersions extends \JKingWeb\Arsse\Test\AbstractTest {
public function setUp() {
$this->clearData();
}
public function testFetchVersionList() {
$exp = new Response(200, ['apiLevels' => ['v1-2']]);
$h = new REST\NextCloudNews\Versions();
$h = new Versions;
$req = new Request("GET", "/");
$res = $h->dispatch($req);
$this->assertEquals($exp, $res);
@ -31,7 +32,7 @@ class TestNCNVersionDiscovery extends Test\AbstractTest {
public function testRespondToOptionsRequest() {
$exp = new Response(204, "", "", ["Allow: HEAD,GET"]);
$h = new REST\NextCloudNews\Versions();
$h = new Versions;
$req = new Request("OPTIONS", "/");
$res = $h->dispatch($req);
$this->assertEquals($exp, $res);
@ -39,7 +40,7 @@ class TestNCNVersionDiscovery extends Test\AbstractTest {
public function testUseIncorrectMethod() {
$exp = new Response(405, "", "", ["Allow: HEAD,GET"]);
$h = new REST\NextCloudNews\Versions();
$h = new Versions;
$req = new Request("POST", "/");
$res = $h->dispatch($req);
$this->assertEquals($exp, $res);
@ -47,7 +48,7 @@ class TestNCNVersionDiscovery extends Test\AbstractTest {
public function testUseIncorrectPath() {
$exp = new Response(404);
$h = new REST\NextCloudNews\Versions();
$h = new Versions;
$req = new Request("GET", "/ook");
$res = $h->dispatch($req);
$this->assertEquals($exp, $res);

View file

@ -4,8 +4,13 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\REST\TinyTinyRSS;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\User;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Service;
use JKingWeb\Arsse\REST\Request;
use JKingWeb\Arsse\REST\Response;
use JKingWeb\Arsse\Test\Result;
@ -18,7 +23,7 @@ use Phake;
/** @covers \JKingWeb\Arsse\REST\TinyTinyRSS\API<extended>
* @covers \JKingWeb\Arsse\REST\TinyTinyRSS\Exception */
class TestTinyTinyAPI extends Test\AbstractTest {
class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest {
protected $h;
protected $folders = [
['id' => 5, 'parent' => 3, 'children' => 0, 'feeds' => 1, 'name' => "Local"],
@ -161,7 +166,7 @@ LONG_STRING;
'expires' => "2112-12-21 21:12:00",
'user' => Arsse::$user->id,
]);
$this->h = new REST\TinyTinyRSS\API();
$this->h = new API();
}
public function tearDown() {

View file

@ -4,14 +4,19 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\REST\TinyTinyRSS;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\User;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\REST\TinyTinyRSS\Icon;
use JKingWeb\Arsse\REST\Request;
use JKingWeb\Arsse\REST\Response;
use Phake;
/** @covers \JKingWeb\Arsse\REST\TinyTinyRSS\Icon<extended> */
class TestTinyTinyIcon extends Test\AbstractTest {
class TestIcon extends \JKingWeb\Arsse\Test\AbstractTest {
protected $h;
public function setUp() {
@ -20,7 +25,7 @@ class TestTinyTinyIcon extends Test\AbstractTest {
// create a mock user manager
// create a mock database interface
Arsse::$db = Phake::mock(Database::class);
$this->h = new REST\TinyTinyRSS\Icon();
$this->h = new Icon();
}
public function tearDown() {

View file

@ -4,13 +4,17 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\Service;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Service;
use JKingWeb\Arsse\Misc\Date;
use Phake;
/** @covers \JKingWeb\Arsse\Service */
class TestService extends Test\AbstractTest {
class TestService extends \JKingWeb\Arsse\Test\AbstractTest {
protected $srv;
public function setUp() {

View file

@ -4,42 +4,47 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\User;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\User;
use JKingWeb\Arsse\User\Driver;
use Phake;
/** @covers \JKingWeb\Arsse\User */
class TestAuthorization extends Test\AbstractTest {
class TestAuthorization extends \JKingWeb\Arsse\Test\AbstractTest {
const USERS = [
'user@example.com' => User\Driver::RIGHTS_NONE,
'user@example.org' => User\Driver::RIGHTS_NONE,
'dman@example.com' => User\Driver::RIGHTS_DOMAIN_MANAGER,
'dman@example.org' => User\Driver::RIGHTS_DOMAIN_MANAGER,
'dadm@example.com' => User\Driver::RIGHTS_DOMAIN_ADMIN,
'dadm@example.org' => User\Driver::RIGHTS_DOMAIN_ADMIN,
'gman@example.com' => User\Driver::RIGHTS_GLOBAL_MANAGER,
'gman@example.org' => User\Driver::RIGHTS_GLOBAL_MANAGER,
'gadm@example.com' => User\Driver::RIGHTS_GLOBAL_ADMIN,
'gadm@example.org' => User\Driver::RIGHTS_GLOBAL_ADMIN,
'user@example.com' => Driver::RIGHTS_NONE,
'user@example.org' => Driver::RIGHTS_NONE,
'dman@example.com' => Driver::RIGHTS_DOMAIN_MANAGER,
'dman@example.org' => Driver::RIGHTS_DOMAIN_MANAGER,
'dadm@example.com' => Driver::RIGHTS_DOMAIN_ADMIN,
'dadm@example.org' => Driver::RIGHTS_DOMAIN_ADMIN,
'gman@example.com' => Driver::RIGHTS_GLOBAL_MANAGER,
'gman@example.org' => Driver::RIGHTS_GLOBAL_MANAGER,
'gadm@example.com' => Driver::RIGHTS_GLOBAL_ADMIN,
'gadm@example.org' => Driver::RIGHTS_GLOBAL_ADMIN,
// invalid rights levels
'bad1@example.com' => User\Driver::RIGHTS_NONE+1,
'bad1@example.org' => User\Driver::RIGHTS_NONE+1,
'bad2@example.com' => User\Driver::RIGHTS_DOMAIN_MANAGER+1,
'bad2@example.org' => User\Driver::RIGHTS_DOMAIN_MANAGER+1,
'bad3@example.com' => User\Driver::RIGHTS_DOMAIN_ADMIN+1,
'bad3@example.org' => User\Driver::RIGHTS_DOMAIN_ADMIN+1,
'bad4@example.com' => User\Driver::RIGHTS_GLOBAL_MANAGER+1,
'bad4@example.org' => User\Driver::RIGHTS_GLOBAL_MANAGER+1,
'bad5@example.com' => User\Driver::RIGHTS_GLOBAL_ADMIN+1,
'bad5@example.org' => User\Driver::RIGHTS_GLOBAL_ADMIN+1,
'bad1@example.com' => Driver::RIGHTS_NONE+1,
'bad1@example.org' => Driver::RIGHTS_NONE+1,
'bad2@example.com' => Driver::RIGHTS_DOMAIN_MANAGER+1,
'bad2@example.org' => Driver::RIGHTS_DOMAIN_MANAGER+1,
'bad3@example.com' => Driver::RIGHTS_DOMAIN_ADMIN+1,
'bad3@example.org' => Driver::RIGHTS_DOMAIN_ADMIN+1,
'bad4@example.com' => Driver::RIGHTS_GLOBAL_MANAGER+1,
'bad4@example.org' => Driver::RIGHTS_GLOBAL_MANAGER+1,
'bad5@example.com' => Driver::RIGHTS_GLOBAL_ADMIN+1,
'bad5@example.org' => Driver::RIGHTS_GLOBAL_ADMIN+1,
];
const LEVELS = [
User\Driver::RIGHTS_NONE,
User\Driver::RIGHTS_DOMAIN_MANAGER,
User\Driver::RIGHTS_DOMAIN_ADMIN,
User\Driver::RIGHTS_GLOBAL_MANAGER,
User\Driver::RIGHTS_GLOBAL_ADMIN,
Driver::RIGHTS_NONE,
Driver::RIGHTS_DOMAIN_MANAGER,
Driver::RIGHTS_DOMAIN_ADMIN,
Driver::RIGHTS_GLOBAL_MANAGER,
Driver::RIGHTS_GLOBAL_ADMIN,
];
const DOMAINS = [
'@example.com',
@ -49,7 +54,7 @@ class TestAuthorization extends Test\AbstractTest {
protected $data;
public function setUp(string $drv = Test\User\DriverInternalMock::class, string $db = null) {
public function setUp(string $drv = \JkingWeb\Arsse\Test\User\DriverInternalMock::class, string $db = null) {
$this->clearData();
$conf = new Conf();
$conf->userDriver = $drv;
@ -91,7 +96,7 @@ class TestAuthorization extends Test\AbstractTest {
public function testRegularUserLogic() {
foreach (self::USERS as $actor => $rights) {
if ($rights != User\Driver::RIGHTS_NONE) {
if ($rights != Driver::RIGHTS_NONE) {
continue;
}
Arsse::$user->auth($actor, "");
@ -118,7 +123,7 @@ class TestAuthorization extends Test\AbstractTest {
public function testDomainManagerLogic() {
foreach (self::USERS as $actor => $actorRights) {
if ($actorRights != User\Driver::RIGHTS_DOMAIN_MANAGER) {
if ($actorRights != Driver::RIGHTS_DOMAIN_MANAGER) {
continue;
}
$actorDomain = substr($actor, strrpos($actor, "@")+1);
@ -139,7 +144,7 @@ class TestAuthorization extends Test\AbstractTest {
}
// and they should only be able to set their own rights to regular user
foreach (self::LEVELS as $level) {
if ($actor==$affected && in_array($level, [User\Driver::RIGHTS_NONE, User\Driver::RIGHTS_DOMAIN_MANAGER])) {
if ($actor==$affected && in_array($level, [User\Driver::RIGHTS_NONE, Driver::RIGHTS_DOMAIN_MANAGER])) {
$this->assertTrue(Arsse::$user->authorize($affected, "userRightsSet", $level), "User $actor acted properly for $affected settings rights level $level, but the action was denied.");
} else {
$this->assertFalse(Arsse::$user->authorize($affected, "userRightsSet", $level), "User $actor acted improperly for $affected settings rights level $level, but the action was allowed.");
@ -159,7 +164,7 @@ class TestAuthorization extends Test\AbstractTest {
public function testDomainAdministratorLogic() {
foreach (self::USERS as $actor => $actorRights) {
if ($actorRights != User\Driver::RIGHTS_DOMAIN_ADMIN) {
if ($actorRights != Driver::RIGHTS_DOMAIN_ADMIN) {
continue;
}
$actorDomain = substr($actor, strrpos($actor, "@")+1);
@ -201,7 +206,7 @@ class TestAuthorization extends Test\AbstractTest {
public function testGlobalManagerLogic() {
foreach (self::USERS as $actor => $actorRights) {
if ($actorRights != User\Driver::RIGHTS_GLOBAL_MANAGER) {
if ($actorRights != Driver::RIGHTS_GLOBAL_MANAGER) {
continue;
}
$actorDomain = substr($actor, strrpos($actor, "@")+1);
@ -218,7 +223,7 @@ class TestAuthorization extends Test\AbstractTest {
}
// and they should only be able to set their own rights to regular user
foreach (self::LEVELS as $level) {
if ($actor==$affected && in_array($level, [User\Driver::RIGHTS_NONE, User\Driver::RIGHTS_GLOBAL_MANAGER])) {
if ($actor==$affected && in_array($level, [User\Driver::RIGHTS_NONE, Driver::RIGHTS_GLOBAL_MANAGER])) {
$this->assertTrue(Arsse::$user->authorize($affected, "userRightsSet", $level), "User $actor acted properly for $affected settings rights level $level, but the action was denied.");
} else {
$this->assertFalse(Arsse::$user->authorize($affected, "userRightsSet", $level), "User $actor acted improperly for $affected settings rights level $level, but the action was allowed.");
@ -234,7 +239,7 @@ class TestAuthorization extends Test\AbstractTest {
public function testGlobalAdministratorLogic() {
foreach (self::USERS as $actor => $actorRights) {
if ($actorRights != User\Driver::RIGHTS_GLOBAL_ADMIN) {
if ($actorRights != Driver::RIGHTS_GLOBAL_ADMIN) {
continue;
}
Arsse::$user->auth($actor, "");
@ -302,7 +307,7 @@ class TestAuthorization extends Test\AbstractTest {
public function testExternalExceptionLogic() {
// set up the test for an external driver
$this->setUp(Test\User\DriverExternalMock::class, Test\User\Database::class);
$this->setUp(\JKingWeb\Arsse\Test\User\DriverExternalMock::class, \JKingWeb\Arsse\Test\User\Database::class);
// run the previous test with the external driver set up
$this->testInternalExceptionLogic();
}
@ -318,7 +323,7 @@ class TestAuthorization extends Test\AbstractTest {
}
try {
call_user_func_array(array(Arsse::$user, $func), $args);
} catch (User\ExceptionAuthz $e) {
} catch (\JKingWeb\Arsse\User\ExceptionAuthz $e) {
$err[] = $func;
}
}

View file

@ -4,14 +4,14 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\User;
/** @covers \JKingWeb\Arsse\User */
class TestUserMockExternal extends Test\AbstractTest {
use Test\User\CommonTests;
class TestMockExternal extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\User\CommonTests;
const USER1 = "john.doe@example.com";
const USER2 = "jane.doe@example.com";
public $drv = Test\User\DriverExternalMock::class;
public $drv = \JKingWeb\Arsse\Test\User\DriverExternalMock::class;
}

View file

@ -4,16 +4,18 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\User;
use JKingWeb\Arsse\Arsse;
/** @covers \JKingWeb\Arsse\User */
class TestUserMockInternal extends Test\AbstractTest {
use Test\User\CommonTests;
class TestMockInternal extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\User\CommonTests;
const USER1 = "john.doe@example.com";
const USER2 = "jane.doe@example.com";
public $drv = Test\User\DriverInternalMock::class;
public $drv = \JKingWeb\Arsse\Test\User\DriverInternalMock::class;
public function setUpSeries() {
Arsse::$db = null;

View file

@ -4,17 +4,17 @@
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace JKingWeb\Arsse;
namespace JKingWeb\Arsse\TestCase\User;
/**
* @covers \JKingWeb\Arsse\User
* @covers \JKingWeb\Arsse\User\Internal\Driver
* @covers \JKingWeb\Arsse\User\Internal\InternalFunctions */
class TestUserInternalDriver extends Test\AbstractTest {
use Test\User\CommonTests;
class TestInternal extends \JKingWeb\Arsse\Test\AbstractTest {
use \JKingWeb\Arsse\Test\User\CommonTests;
const USER1 = "john.doe@example.com";
const USER2 = "jane.doe@example.com";
public $drv = User\Internal\Driver::class;
public $drv = \JKingWeb\Arsse\User\Internal\Driver::class;
}

View file

@ -89,7 +89,7 @@ trait Setup {
foreach ($info['rows'] as $index => $row) {
$this->assertCount(sizeof($cols), $row, "The number of values for array index $index does not match the number of fields");
$row = array_combine($cols, $row);
foreach($data as $index => $test) {
foreach ($data as $index => $test) {
foreach ($test as $col => $value) {
switch ($types[$col]) {
case "datetime":
@ -106,7 +106,7 @@ trait Setup {
break;
}
}
if($row===$test) {
if ($row===$test) {
$data[$index] = $test;
break;
}

View file

@ -21,9 +21,9 @@
<file>cases/Exception/TestException.php</file>
</testsuite>
<testsuite name="Localization">
<file>cases/Lang/TestLang.php</file>
<file>cases/Lang/TestLangComplex.php</file>
<file>cases/Lang/TestLangErrors.php</file>
<file>cases/Lang/TestBasic.php</file>
<file>cases/Lang/TestComplex.php</file>
<file>cases/Lang/TestErrors.php</file>
</testsuite>
<testsuite name="Configuration">
<file>cases/Conf/TestConf.php</file>
@ -33,24 +33,24 @@
<file>cases/Misc/TestContext.php</file>
</testsuite>
<testsuite name="User management">
<file>cases/User/TestUserMockInternal.php</file>
<file>cases/User/TestUserMockExternal.php</file>
<file>cases/User/TestUserInternalDriver.php</file>
<file>cases/User/TestMockInternal.php</file>
<file>cases/User/TestMockExternal.php</file>
<file>cases/User/TestInternal.php</file>
<file>cases/User/TestAuthorization.php</file>
</testsuite>
<testsuite name="Feed parser">
<file>cases/Feed/TestFeedFetching.php</file>
<file>cases/Feed/TestFetching.php</file>
<file>cases/Feed/TestFeed.php</file>
</testsuite>
<testsuite name="Database drivers">
<file>cases/Db/TestTransaction.php</file>
<file>cases/Db/TestResultAggregate.php</file>
<file>cases/Db/TestResultEmpty.php</file>
<file>cases/Db/SQLite3/TestDbResultSQLite3.php</file>
<file>cases/Db/SQLite3/TestDbStatementSQLite3.php</file>
<file>cases/Db/SQLite3/TestDbDriverCreationSQLite3.php</file>
<file>cases/Db/SQLite3/TestDbDriverSQLite3.php</file>
<file>cases/Db/SQLite3/TestDbUpdateSQLite3.php</file>
<file>cases/Db/SQLite3/TestResult.php</file>
<file>cases/Db/SQLite3/TestStatement.php</file>
<file>cases/Db/SQLite3/TestCreation.php</file>
<file>cases/Db/SQLite3/TestDriver.php</file>
<file>cases/Db/SQLite3/TestUpdate.php</file>
<file>cases/Db/SQLite3PDO/TestDbResultSQLite3PDO.php</file>
<file>cases/Db/SQLite3PDO/TestDbStatementSQLite3PDO.php</file>
@ -59,16 +59,16 @@
<file>cases/Db/SQLite3PDO/TestDbUpdateSQLite3PDO.php</file>
</testsuite>
<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>
<file>cases/Db/SQLite3/Database/TestDatabaseSessionSQLite3.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseFolderSQLite3.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseFeedSQLite3.php</file>
<file>cases/Db/SQLite3/Database/TestDatabaseSubscriptionSQLite3.php</file>
<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/SQLite3/Database/TestMiscellany.php</file>
<file>cases/Db/SQLite3/Database/TestMeta.php</file>
<file>cases/Db/SQLite3/Database/TestUser.php</file>
<file>cases/Db/SQLite3/Database/TestSession.php</file>
<file>cases/Db/SQLite3/Database/TestFolder.php</file>
<file>cases/Db/SQLite3/Database/TestFeed.php</file>
<file>cases/Db/SQLite3/Database/TestSubscription.php</file>
<file>cases/Db/SQLite3/Database/TestArticle.php</file>
<file>cases/Db/SQLite3/Database/TestLabel.php</file>
<file>cases/Db/SQLite3/Database/TestCleanup.php</file>
<file>cases/Db/SQLite3PDO/Database/TestDatabaseMiscellanySQLite3PDO.php</file>
<file>cases/Db/SQLite3PDO/Database/TestDatabaseUserSQLite3PDO.php</file>
@ -82,12 +82,12 @@
</testsuite>
<testsuite name="Controllers">
<testsuite name="NCNv1">
<file>cases/REST/NextCloudNews/TestNCNVersionDiscovery.php</file>
<file>cases/REST/NextCloudNews/TestNCNV1_2.php</file>
<file>cases/REST/NextCloudNews/TestVersions.php</file>
<file>cases/REST/NextCloudNews/TestV1_2.php</file>
</testsuite>
<testsuite name="TTRSS">
<file>cases/REST/TinyTinyRSS/TestTinyTinyAPI.php</file>
<file>cases/REST/TinyTinyRSS/TestTinyTinyIcon.php</file>
<file>cases/REST/TinyTinyRSS/TestAPI.php</file>
<file>cases/REST/TinyTinyRSS/TestIcon.php</file>
</testsuite>
</testsuite>
<testsuite name="Refresh service">