1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2025-01-05 07:22:40 +00:00

Correct most remaining test bugs

This commit is contained in:
J. King 2024-12-24 22:58:58 -05:00
parent f1d3055f4c
commit 93c322bdfa
12 changed files with 42 additions and 34 deletions

View file

@ -24,4 +24,6 @@ if (function_exists("xdebug_set_filter")) {
} }
} }
\Phake::setClient(\Phake::CLIENT_PHPUNIT9); if (class_exists(\Phake::class)) {
\Phake::setClient(\Phake::CLIENT_PHPUNIT9);
}

View file

@ -99,11 +99,11 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
public function testFailToStartTheForkingDaemon(): void { public function testFailToStartTheForkingDaemon(): void {
$srv = \Phake::mock(Service::class); $srv = \Phake::mock(Service::class);
$daemon = \Phake::mock(Daemon::class); $daemon = \Phake::mock(Daemon::class);
\Phake::when($srv)->watch->thenReturns(new \DateTimeImmutable); \Phake::when($srv)->watch->thenReturn(new \DateTimeImmutable);
\Phake::when($daemon)->checkPIDFilePath->throws(new Service\Exception("pidDuplicate", ['pid' => 2112])); \Phake::when($daemon)->checkPIDFilePath->thenThrow(new Service\Exception("pidDuplicate", ['pid' => 2112]));
\Phake::when($daemon)->fork->returns(null); \Phake::when($daemon)->fork->thenReturn(null);
\Phake::when(Arsse::$obj)->get(Service::class)->returns($srv); \Phake::when(Arsse::$obj)->get(Service::class)->thenReturn($srv);
\Phake::when(Arsse::$obj)->get(Daemon::class)->returns($daemon); \Phake::when(Arsse::$obj)->get(Daemon::class)->thenReturn($daemon);
$this->assertConsole("arsse.php daemon --fork=arsse.pid", 10809); $this->assertConsole("arsse.php daemon --fork=arsse.pid", 10809);
\Phake::verify($daemon)->checkPIDFilePath("arsse.pid"); \Phake::verify($daemon)->checkPIDFilePath("arsse.pid");
\Phake::verify($daemon, \Phake::never())->fork($this->anything()); \Phake::verify($daemon, \Phake::never())->fork($this->anything());
@ -126,7 +126,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::when(Arsse::$db)->feedUpdate(2, true)->thenThrow(new \JKingWeb\Arsse\Feed\Exception("", ['url' => "http://example.com/"], $this->mockGuzzleException(ClientException::class, "", 404))); \Phake::when(Arsse::$db)->feedUpdate(2, true)->thenThrow(new \JKingWeb\Arsse\Feed\Exception("", ['url' => "http://example.com/"], $this->mockGuzzleException(ClientException::class, "", 404)));
$this->assertConsole($cmd, $exitStatus, $output); $this->assertConsole($cmd, $exitStatus, $output);
\Phake::verify($this->cli)->loadConf(); \Phake::verify($this->cli)->loadConf();
\Phake::verify($this->dbMock)->feedUpdate(); \Phake::verify(Arsse::$db)->feedUpdate(\Phake::anyParameters());
} }
public function provideFeedUpdates(): iterable { public function provideFeedUpdates(): iterable {
@ -144,7 +144,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::when($conf)->exportFile("bad.conf", true)->thenThrow(new \JKingWeb\Arsse\Conf\Exception("fileUnwritable")); \Phake::when($conf)->exportFile("bad.conf", true)->thenThrow(new \JKingWeb\Arsse\Conf\Exception("fileUnwritable"));
\Phake::when(Arsse::$obj)->get(Conf::class)->thenReturn($conf); \Phake::when(Arsse::$obj)->get(Conf::class)->thenReturn($conf);
$this->assertConsole($cmd, $exitStatus); $this->assertConsole($cmd, $exitStatus);
\Phake::verify($this->cli)->loadConf(); \Phake::verify($this->cli, \Phake::never())->loadConf();
\Phake::verify($conf)->exportFile($file, true); \Phake::verify($conf)->exportFile($file, true);
} }
@ -262,7 +262,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
\Phake::when(Arsse::$user)->passwordSet->thenReturnCallback($passwordChange); \Phake::when(Arsse::$user)->passwordSet->thenReturnCallback($passwordChange);
$fever = \Phake::mock(FeverUser::class); $fever = \Phake::mock(FeverUser::class);
\Phake::when($fever)->register->thenReturnCallback($passwordChange); \Phake::when($fever)->register->thenReturnCallback($passwordChange);
\Phake::when(Arsse::$obj)->get(FeverUser::class)->returns($fever); \Phake::when(Arsse::$obj)->get(FeverUser::class)->thenReturn($fever);
$this->assertConsole($cmd, $exitStatus, $output); $this->assertConsole($cmd, $exitStatus, $output);
} }
@ -308,9 +308,9 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
public function testExportToOpml(string $cmd, int $exitStatus, string $file, string $user, bool $flat): void { public function testExportToOpml(string $cmd, int $exitStatus, string $file, string $user, bool $flat): void {
$opml = \Phake::mock(OPML::class); $opml = \Phake::mock(OPML::class);
\Phake::when($opml)->exportFile("php://output", $user, $flat)->thenReturn(true); \Phake::when($opml)->exportFile("php://output", $user, $flat)->thenReturn(true);
\Phake::when($opml)->exportFile("good.opml", $user, $flat)->thenRreturn(true); \Phake::when($opml)->exportFile("good.opml", $user, $flat)->thenReturn(true);
\Phake::when($opml)->exportFile("bad.opml", $user, $flat)->thenThrow(new \JKingWeb\Arsse\ImportExport\Exception("fileUnwritable")); \Phake::when($opml)->exportFile("bad.opml", $user, $flat)->thenThrow(new \JKingWeb\Arsse\ImportExport\Exception("fileUnwritable"));
\Phake::when(Arsse::$obj)->get(OPML::class)->returns($opml); \Phake::when(Arsse::$obj)->get(OPML::class)->thenReturn($opml);
$this->assertConsole($cmd, $exitStatus); $this->assertConsole($cmd, $exitStatus);
\Phake::verify($this->cli)->loadConf(); \Phake::verify($this->cli)->loadConf();
\Phake::verify($opml)->exportFile($file, $user, $flat); \Phake::verify($opml)->exportFile($file, $user, $flat);

View file

@ -212,7 +212,7 @@ trait SeriesSubscription {
$url = "http://example.com/feed1"; $url = "http://example.com/feed1";
$subID = $this->nextID("arsse_subscriptions"); $subID = $this->nextID("arsse_subscriptions");
Arsse::$db = \Phake::partialMock(Database::class, static::$drv); Arsse::$db = \Phake::partialMock(Database::class, static::$drv);
\Phake::when($db)->feedUpdate->thenReturn(true); \Phake::when(Arsse::$db)->feedUpdate->thenReturn(true);
$this->assertSame($subID, Arsse::$db->subscriptionAdd($this->user, $url)); $this->assertSame($subID, Arsse::$db->subscriptionAdd($this->user, $url));
\Phake::verify(Arsse::$db, \Phake::never())->feedUpdate(\Phake::anyParameters()); \Phake::verify(Arsse::$db, \Phake::never())->feedUpdate(\Phake::anyParameters());
$state = $this->primeExpectations($this->data, [ $state = $this->primeExpectations($this->data, [
@ -234,7 +234,7 @@ trait SeriesSubscription {
Arsse::$db = \Phake::partialMock(Database::class, static::$drv); Arsse::$db = \Phake::partialMock(Database::class, static::$drv);
\Phake::when(Arsse::$db)->feedUpdate->thenReturn(true); \Phake::when(Arsse::$db)->feedUpdate->thenReturn(true);
$this->assertSame($subID, Arsse::$db->subscriptionAdd($this->user, $url, "", "", false)); $this->assertSame($subID, Arsse::$db->subscriptionAdd($this->user, $url, "", "", false));
\Phake::verify($db)->feedUpdate($feedID, true, false); \Phake::verify(Arsse::$db)->feedUpdate($feedID, true, false);
$state = $this->primeExpectations($this->data, [ $state = $this->primeExpectations($this->data, [
'arsse_feeds' => ['id','url','username','password'], 'arsse_feeds' => ['id','url','username','password'],
'arsse_subscriptions' => ['id','owner','feed'], 'arsse_subscriptions' => ['id','owner','feed'],

View file

@ -20,7 +20,7 @@ class TestTransaction extends \JKingWeb\Arsse\Test\AbstractTest {
$drv = \Phake::mock(\JKingWeb\Arsse\Db\SQLite3\Driver::class); $drv = \Phake::mock(\JKingWeb\Arsse\Db\SQLite3\Driver::class);
\Phake::when($drv)->savepointRelease->thenReturn(true); \Phake::when($drv)->savepointRelease->thenReturn(true);
\Phake::when($drv)->savepointUndo->thenReturn(true); \Phake::when($drv)->savepointUndo->thenReturn(true);
\Phake::when($drv)->savepointCreate->thenReturn(1, 2); \Phake::when($drv)->savepointCreate->thenReturn(1)->thenReturn(2);
$this->drv = $drv; $this->drv = $drv;
} }

View file

@ -465,7 +465,7 @@ class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest {
} }
public function testOutputToXml(): void { public function testOutputToXml(): void {
$this->hMock->processRequest->thenReturn([ \Phake::when($this->hMock)->processRequest->thenReturn([
'items' => $this->articles['rest'], 'items' => $this->articles['rest'],
'total_items' => 1024, 'total_items' => 1024,
]); ]);

View file

@ -16,6 +16,7 @@ use JKingWeb\Arsse\Database;
use JKingWeb\Arsse\Misc\HTTP; use JKingWeb\Arsse\Misc\HTTP;
use JKingWeb\Arsse\Db\Transaction; use JKingWeb\Arsse\Db\Transaction;
use JKingWeb\Arsse\Db\ExceptionInput; use JKingWeb\Arsse\Db\ExceptionInput;
use JKingWeb\Arsse\Factory;
use JKingWeb\Arsse\REST\Miniflux\V1; use JKingWeb\Arsse\REST\Miniflux\V1;
use JKingWeb\Arsse\Feed\Exception as FeedException; use JKingWeb\Arsse\Feed\Exception as FeedException;
use JKingWeb\Arsse\ImportExport\Exception as ImportException; use JKingWeb\Arsse\ImportExport\Exception as ImportException;
@ -75,6 +76,7 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
self::setConf(); self::setConf();
$this->transaction = \Phake::mock(Transaction::class); $this->transaction = \Phake::mock(Transaction::class);
// create mock timestamps // create mock timestamps
Arsse::$obj = \Phake::mock(Factory::class);
\Phake::when(Arsse::$obj)->get(\DateTimeImmutable::class)->thenReturn(new \DateTimeImmutable(self::NOW)); \Phake::when(Arsse::$obj)->get(\DateTimeImmutable::class)->thenReturn(new \DateTimeImmutable(self::NOW));
// create a mock database interface // create a mock database interface
Arsse::$db = \Phake::mock(Database::class); Arsse::$db = \Phake::mock(Database::class);
@ -237,7 +239,7 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
/** @dataProvider provideUserModifications */ /** @dataProvider provideUserModifications */
public function testModifyAUser(bool $admin, string $url, array $body, $in1, $out1, $in2, $out2, $in3, $out3, ResponseInterface $exp): void { public function testModifyAUser(bool $admin, string $url, array $body, $in1, $out1, $in2, $out2, $in3, $out3, ResponseInterface $exp): void {
Arsse::$user = \Phake::mock(User::class); Arsse::$user = \Phake::mock(User::class);
\Phake::when(Arsse::$user)->begin->thenReturn($this->transaction->get()); \Phake::when(Arsse::$user)->begin->thenReturn($this->transaction);
\Phake::when(Arsse::$user)->propertiesGet->thenReturn(['num' => 1, 'admin' => true]); \Phake::when(Arsse::$user)->propertiesGet->thenReturn(['num' => 1, 'admin' => true]);
\Phake::when(Arsse::$user)->propertiesGet("john.doe@example.com", $this->anything())->thenReturn(['num' => 2, 'admin' => $admin]); \Phake::when(Arsse::$user)->propertiesGet("john.doe@example.com", $this->anything())->thenReturn(['num' => 2, 'admin' => $admin]);
\Phake::when(Arsse::$user)->propertiesGet("ook", $this->anything())->thenReturn(['num' => 2, 'admin' => $admin]); \Phake::when(Arsse::$user)->propertiesGet("ook", $this->anything())->thenReturn(['num' => 2, 'admin' => $admin]);
@ -306,7 +308,7 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
/** @dataProvider provideUserAdditions */ /** @dataProvider provideUserAdditions */
public function testAddAUser(array $body, $in1, $out1, $in2, $out2, ResponseInterface $exp): void { public function testAddAUser(array $body, $in1, $out1, $in2, $out2, ResponseInterface $exp): void {
Arsse::$user = \Phake::mock(User::class); Arsse::$user = \Phake::mock(User::class);
\Phake::when(Arsse::$user)->begin->thenReturn($this->transaction->get()); \Phake::when(Arsse::$user)->begin->thenReturn($this->transaction);
\Phake::when(Arsse::$user)->propertiesGet->thenReturn(['num' => 2, 'admin' => false]); \Phake::when(Arsse::$user)->propertiesGet->thenReturn(['num' => 2, 'admin' => false]);
\Phake::when(Arsse::$user)->propertiesGet("john.doe@example.com", $this->anything())->thenReturn(['num' => 1, 'admin' => true]); \Phake::when(Arsse::$user)->propertiesGet("john.doe@example.com", $this->anything())->thenReturn(['num' => 1, 'admin' => true]);
if ($out1 instanceof \Exception) { if ($out1 instanceof \Exception) {
@ -929,7 +931,7 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest {
public function testImport($out, ResponseInterface $exp): void { public function testImport($out, ResponseInterface $exp): void {
$opml = \Phake::mock(OPML::class); $opml = \Phake::mock(OPML::class);
\Phake::when(Arsse::$obj)->get(OPML::class)->thenReturn($opml); \Phake::when(Arsse::$obj)->get(OPML::class)->thenReturn($opml);
$action = ($out instanceof \Exception) ? "thenThrow" : "thenRreturn"; $action = ($out instanceof \Exception) ? "thenThrow" : "thenReturn";
\Phake::when($opml)->import->$action($out); \Phake::when($opml)->import->$action($out);
$this->assertMessage($exp, $this->req("POST", "/import", "IMPORT DATA")); $this->assertMessage($exp, $this->req("POST", "/import", "IMPORT DATA"));
\Phake::verify($opml)->import(Arsse::$user->id, "IMPORT DATA"); \Phake::verify($opml)->import(Arsse::$user->id, "IMPORT DATA");

View file

@ -491,9 +491,9 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
'starredCount' => 5, 'starredCount' => 5,
'newestItemId' => 4758915, 'newestItemId' => 4758915,
]; ];
\Phake::when(Arsse::$db)->subscriptionList($this->userId)->theneturn(new Result([]))->thenReturn(new Result($this->v($this->feeds['db']))); \Phake::when(Arsse::$db)->subscriptionList($this->userId)->thenReturn(new Result([]))->thenReturn(new Result($this->v($this->feeds['db'])));
\Phake::when(Arsse::$db)->articleStarred($this->userId)->thenReturn($this->v(['total' => 0]))->thenReturn($this->v(['total' => 5])); \Phake::when(Arsse::$db)->articleStarred($this->userId)->thenReturn($this->v(['total' => 0]))->thenReturn($this->v(['total' => 5]));
\Phake::when(Arsse::$db)->editionLatest($this->userId)->thenReturns(0)->thenReturn(4758915); \Phake::when(Arsse::$db)->editionLatest($this->userId)->thenReturn(0)->thenReturn(4758915);
$exp = HTTP::respJson($exp1); $exp = HTTP::respJson($exp1);
$this->assertMessage($exp, $this->req("GET", "/feeds")); $this->assertMessage($exp, $this->req("GET", "/feeds"));
$exp = HTTP::respJson($exp2); $exp = HTTP::respJson($exp2);
@ -777,7 +777,7 @@ class TestV1_2 extends \JKingWeb\Arsse\Test\AbstractTest {
$this->assertMessage($exp, $this->req("PUT", "/items/47/unread")); $this->assertMessage($exp, $this->req("PUT", "/items/47/unread"));
$this->assertMessage($exp, $this->req("PUT", "/items/1/2112/star")); $this->assertMessage($exp, $this->req("PUT", "/items/1/2112/star"));
$this->assertMessage($exp, $this->req("PUT", "/items/4400/1337/unstar")); $this->assertMessage($exp, $this->req("PUT", "/items/4400/1337/unstar"));
\Phake::verify(Arsse::$db, \Phake::times(8))->articleMark($this->userId, \Phake::anyParameters()); \Phake::verify(Arsse::$db, \Phake::times(8))->articleMark($this->userId, \Phake::ignoreRemaining());
} }
public function testChangeMarksOfMultipleArticles(): void { public function testChangeMarksOfMultipleArticles(): void {

View file

@ -19,6 +19,7 @@ use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\ServerRequest; use GuzzleHttp\Psr7\ServerRequest;
use JKingWeb\Arsse\Factory;
/** @covers \JKingWeb\Arsse\REST */ /** @covers \JKingWeb\Arsse\REST */
class TestREST extends \JKingWeb\Arsse\Test\AbstractTest { class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
@ -294,8 +295,9 @@ class TestREST extends \JKingWeb\Arsse\Test\AbstractTest {
return $req; return $req;
}); });
if ($called) { if ($called) {
Arsse::$obj = \Phake::mock(Factory::class);
$hMock = \Phake::mock($class); $hMock = \Phake::mock($class);
$hMock->dispatch->thenReturn(HTTP::respEmpty(204)); \Phake::when($hMock)->dispatch->thenReturn(HTTP::respEmpty(204));
\Phake::when(Arsse::$obj)->get($class)->thenReturn($hMock); \Phake::when(Arsse::$obj)->get($class)->thenReturn($hMock);
} }
$out = $rMock->dispatch($req); $out = $rMock->dispatch($req);

View file

@ -16,6 +16,7 @@ use JKingWeb\Arsse\Misc\HTTP;
use JKingWeb\Arsse\Context\Context; use JKingWeb\Arsse\Context\Context;
use JKingWeb\Arsse\Db\ExceptionInput; use JKingWeb\Arsse\Db\ExceptionInput;
use JKingWeb\Arsse\Db\Transaction; use JKingWeb\Arsse\Db\Transaction;
use JKingWeb\Arsse\Factory;
use JKingWeb\Arsse\REST\TinyTinyRSS\API; use JKingWeb\Arsse\REST\TinyTinyRSS\API;
use JKingWeb\Arsse\Feed\Exception as FeedException; use JKingWeb\Arsse\Feed\Exception as FeedException;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
@ -129,9 +130,10 @@ LONG_STRING;
} }
public function setUp(): void { public function setUp(): void {
parent::setUp(); self::clearData();
self::setConf(); self::setConf();
// create mock timestamps // create mock timestamps
Arsse::$obj = \Phake::mock(Factory::class);
\Phake::when(Arsse::$obj)->get(\DateTimeImmutable::class)->thenReturn(new \DateTimeImmutable(self::NOW)); \Phake::when(Arsse::$obj)->get(\DateTimeImmutable::class)->thenReturn(new \DateTimeImmutable(self::NOW));
// create a mock user manager // create a mock user manager
$this->userId = "john.doe@example.com"; $this->userId = "john.doe@example.com";
@ -210,8 +212,8 @@ LONG_STRING;
\Phake::when(Arsse::$user)->auth->thenReturn(false); \Phake::when(Arsse::$user)->auth->thenReturn(false);
\Phake::when(Arsse::$user)->auth("john.doe@example.com", "secret")->thenReturn(true); \Phake::when(Arsse::$user)->auth("john.doe@example.com", "secret")->thenReturn(true);
\Phake::when(Arsse::$user)->auth("jane.doe@example.com", "superman")->thenReturn(true); \Phake::when(Arsse::$user)->auth("jane.doe@example.com", "superman")->thenReturn(true);
\Phake::when(Arsse::$db)->sessionCreate("john.doe@example.com")->thenReturn("PriestsOfSyrinx", "SolarFederation"); \Phake::when(Arsse::$db)->sessionCreate("john.doe@example.com")->thenReturn("PriestsOfSyrinx")->thenReturn("SolarFederation");
\Phake::when(Arsse::$db)->sessionCreate("jane.doe@example.com")->thenReturn("ClockworkAngels", "SevenCitiesOfGold"); \Phake::when(Arsse::$db)->sessionCreate("jane.doe@example.com")->thenReturn("ClockworkAngels")->thenReturn("SevenCitiesOfGold");
if ($sessions instanceof ResponseInterface) { if ($sessions instanceof ResponseInterface) {
$exp1 = $sessions; $exp1 = $sessions;
$exp2 = $sessions; $exp2 = $sessions;
@ -709,7 +711,7 @@ LONG_STRING;
\Phake::when(Arsse::$db)->folderPropertiesGet($this->userId, 42)->thenReturn($this->v(['id' => 42])); \Phake::when(Arsse::$db)->folderPropertiesGet($this->userId, 42)->thenReturn($this->v(['id' => 42]));
\Phake::when(Arsse::$db)->folderPropertiesGet($this->userId, 47)->thenReturn($this->v(['id' => 47])); \Phake::when(Arsse::$db)->folderPropertiesGet($this->userId, 47)->thenReturn($this->v(['id' => 47]));
\Phake::when(Arsse::$db)->folderPropertiesGet($this->userId, 2112)->thenThrow(new ExceptionInput("subjectMissing")); \Phake::when(Arsse::$db)->folderPropertiesGet($this->userId, 2112)->thenThrow(new ExceptionInput("subjectMissing"));
\Phake::when(Arsse::$db)->subscriptionPropertiesSet($this->userId, "*")->thenReturn(true); \Phake::when(Arsse::$db)->subscriptionPropertiesSet($this->userId, $this->anything())->thenReturn(true);
\Phake::when(Arsse::$db)->subscriptionPropertiesSet($this->userId, 4, $this->anything())->thenThrow(new ExceptionInput("idMissing")); \Phake::when(Arsse::$db)->subscriptionPropertiesSet($this->userId, 4, $this->anything())->thenThrow(new ExceptionInput("idMissing"));
\Phake::when(Arsse::$db)->subscriptionList($this->userId)->thenReturn(new Result($this->v($list))); \Phake::when(Arsse::$db)->subscriptionList($this->userId)->thenReturn(new Result($this->v($list)));
$this->assertMessage($exp, $this->req($in)); $this->assertMessage($exp, $this->req($in));
@ -832,8 +834,8 @@ LONG_STRING;
$interval = Arsse::$conf->serviceFrequency; $interval = Arsse::$conf->serviceFrequency;
$valid = (new \DateTimeImmutable("now", new \DateTimezone("UTC")))->sub($interval); $valid = (new \DateTimeImmutable("now", new \DateTimezone("UTC")))->sub($interval);
$invalid = $valid->sub($interval)->sub($interval); $invalid = $valid->sub($interval)->sub($interval);
\Phake::when(Arsse::$db)->metaGet("service_last_checkin")->thenReturn(Date::transform($valid, "sql"), Date::transform($invalid, "sql")); \Phake::when(Arsse::$db)->metaGet("service_last_checkin")->thenReturn(Date::transform($valid, "sql"))->thenReturn(Date::transform($invalid, "sql"));
\Phake::when(Arsse::$db)->subscriptionCount($this->userId)->thenReturn(12, 2); \Phake::when(Arsse::$db)->subscriptionCount($this->userId)->thenReturn(12)->thenReturn(2);
$this->assertMessage($this->respGood(['icons_dir' => "feed-icons", 'icons_url' => "feed-icons", 'daemon_is_running' => true, 'num_feeds' => 12]), $this->req($in)); $this->assertMessage($this->respGood(['icons_dir' => "feed-icons", 'icons_url' => "feed-icons", 'daemon_is_running' => true, 'num_feeds' => 12]), $this->req($in));
$this->assertMessage($this->respGood(['icons_dir' => "feed-icons", 'icons_url' => "feed-icons", 'daemon_is_running' => false, 'num_feeds' => 2]), $this->req($in)); $this->assertMessage($this->respGood(['icons_dir' => "feed-icons", 'icons_url' => "feed-icons", 'daemon_is_running' => false, 'num_feeds' => 2]), $this->req($in));
} }

View file

@ -51,7 +51,7 @@ class TestDaemon extends \JKingWeb\Arsse\Test\AbstractTest {
public function testResolveRelativePaths(string $path, $cwd, $exp): void { public function testResolveRelativePaths(string $path, $cwd, $exp): void {
// set up mock daemon class // set up mock daemon class
\Phake::when($this->daemon)->cwd->thenReturn($cwd); \Phake::when($this->daemon)->cwd->thenReturn($cwd);
$daemon = $this->daemon->get(); $daemon = $this->daemon;
// perform the test // perform the test
$this->AssertSame($exp, $daemon->resolveRelativePath($path)); $this->AssertSame($exp, $daemon->resolveRelativePath($path));
} }
@ -84,7 +84,7 @@ class TestDaemon extends \JKingWeb\Arsse\Test\AbstractTest {
chmod($path."errors/readwrite", 0111); chmod($path."errors/readwrite", 0111);
// set up mock daemon class // set up mock daemon class
\Phake::when($this->daemon)->resolveRelativePath->thenReturn($accessible ? dirname($path.$file) : false); \Phake::when($this->daemon)->resolveRelativePath->thenReturn($accessible ? dirname($path.$file) : false);
$daemon = $this->daemon->get(); $daemon = $this->daemon;
// perform the test // perform the test
if ($exp instanceof \Exception) { if ($exp instanceof \Exception) {
$this->assertException($exp); $this->assertException($exp);
@ -121,7 +121,7 @@ class TestDaemon extends \JKingWeb\Arsse\Test\AbstractTest {
// set up mock daemon class // set up mock daemon class
\Phake::when($this->daemon)->processExists(2112)->thenReturn(true); \Phake::when($this->daemon)->processExists(2112)->thenReturn(true);
\Phake::when($this->daemon)->processExists(42)->thenReturn(false); \Phake::when($this->daemon)->processExists(42)->thenReturn(false);
$daemon = $this->daemon->get(); $daemon = $this->daemon;
// perform the test // perform the test
try { try {
if ($exp instanceof \Exception) { if ($exp instanceof \Exception) {
@ -171,7 +171,7 @@ class TestDaemon extends \JKingWeb\Arsse\Test\AbstractTest {
// set up mock daemon class // set up mock daemon class
\Phake::when($this->daemon)->processExists(2112)->thenReturn(true); \Phake::when($this->daemon)->processExists(2112)->thenReturn(true);
\Phake::when($this->daemon)->processExists(42)->thenReturn(false); \Phake::when($this->daemon)->processExists(42)->thenReturn(false);
$daemon = $this->daemon->get(); $daemon = $this->daemon;
// perform the test // perform the test
try { try {
if ($exp instanceof \Exception) { if ($exp instanceof \Exception) {

View file

@ -36,7 +36,7 @@ class TestService extends \JKingWeb\Arsse\Test\AbstractTest {
$interval = Arsse::$conf->serviceFrequency; $interval = Arsse::$conf->serviceFrequency;
$valid = (new \DateTimeImmutable("now", new \DateTimezone("UTC")))->sub($interval); $valid = (new \DateTimeImmutable("now", new \DateTimezone("UTC")))->sub($interval);
$invalid = $valid->sub($interval)->sub($interval); $invalid = $valid->sub($interval)->sub($interval);
\Phake::when(Arsse::$db)->metaGet("service_last_checkin")->thenReturn(Date::transform($valid, "sql"), Date::transform($invalid, "sql")); \Phake::when(Arsse::$db)->metaGet("service_last_checkin")->thenReturn(Date::transform($valid, "sql"))->thenReturn(Date::transform($invalid, "sql"));
$this->assertTrue(Service::hasCheckedIn()); $this->assertTrue(Service::hasCheckedIn());
$this->assertFalse(Service::hasCheckedIn()); $this->assertFalse(Service::hasCheckedIn());
} }

View file

@ -17,7 +17,7 @@ class TestInternal extends \JKingWeb\Arsse\Test\AbstractTest {
protected $d; protected $d;
public function setUp(): void { public function setUp(): void {
parent::setUp(); self::clearData();
self::setConf(); self::setConf();
// create a mock database interface // create a mock database interface
Arsse::$db = \Phake::mock(Database::class); Arsse::$db = \Phake::mock(Database::class);