Browse Source

Fix remaining Picofeed-related test failures

rpm
J. King 4 years ago
parent
commit
06d3af0ac3
  1. 5
      lib/Feed/Exception.php
  2. 3
      tests/cases/CLI/TestCLI.php
  3. 3
      tests/cases/Database/SeriesSubscription.php
  4. 2
      tests/cases/Feed/TestFetching.php
  5. 9
      tests/cases/REST/TinyTinyRSS/TestAPI.php
  6. 14
      tests/lib/AbstractTest.php

5
lib/Feed/Exception.php

@ -29,10 +29,7 @@ class Exception extends \JKingWeb\Arsse\AbstractException {
$msgID = "tooManyRedirects";
break;
default:
$c = $e->getCode();
if ($c >= 400 && $c < 600) {
$msgID = "transmissionError";
}
$msgID = "transmissionError";
}
} elseif ($e instanceof TooManyRedirectsException) {
$msgID = "maxRedirect";

3
tests/cases/CLI/TestCLI.php

@ -6,6 +6,7 @@
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\CLI;
use GuzzleHttp\Exception\ClientException;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
use JKingWeb\Arsse\User;
@ -81,7 +82,7 @@ class TestCLI extends \JKingWeb\Arsse\Test\AbstractTest {
public function testRefreshAFeed(string $cmd, int $exitStatus, string $output): void {
Arsse::$db = \Phake::mock(Database::class);
\Phake::when(Arsse::$db)->feedUpdate(1, true)->thenReturn(true);
\Phake::when(Arsse::$db)->feedUpdate(2, true)->thenThrow(new \JKingWeb\Arsse\Feed\Exception("http://example.com/", new \PicoFeed\Client\InvalidUrlException));
\Phake::when(Arsse::$db)->feedUpdate(2, true)->thenThrow(new \JKingWeb\Arsse\Feed\Exception("http://example.com/", $this->mockGuzzleException(ClientException::class, "", 404)));
$this->assertConsole($this->cli, $cmd, $exitStatus, $output);
\Phake::verify($this->cli)->loadConf;
\Phake::verify(Arsse::$db)->feedUpdate;

3
tests/cases/Database/SeriesSubscription.php

@ -6,6 +6,7 @@
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\Database;
use GuzzleHttp\Exception\ClientException;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Test\Database;
use JKingWeb\Arsse\Feed\Exception as FeedException;
@ -200,7 +201,7 @@ trait SeriesSubscription {
public function testAddASubscriptionToAnInvalidFeed(): void {
$url = "http://example.org/feed1";
$feedID = $this->nextID("arsse_feeds");
\Phake::when(Arsse::$db)->feedUpdate->thenThrow(new FeedException($url, new \PicoFeed\Client\InvalidUrlException()));
\Phake::when(Arsse::$db)->feedUpdate->thenThrow(new FeedException($url, $this->mockGuzzleException(ClientException::class, "", 404)));
$this->assertException("invalidUrl", "Feed");
try {
Arsse::$db->subscriptionAdd($this->user, $url, "", "", false);

2
tests/cases/Feed/TestFetching.php

@ -58,7 +58,7 @@ class TestFetching extends \JKingWeb\Arsse\Test\AbstractTest {
}
public function testHandleAnOverlyLargeFeed(): void {
$this->markTestIncomplete();
$this->markTestIncomplete("The nicolus/picofeed library does not implement miniflux/picofeed's max-size setting");
Arsse::$conf->fetchSizeLimit = 512;
$this->assertException("maxSize", "Feed");
new Feed(null, $this->base."Fetching/TooLarge");

9
tests/cases/REST/TinyTinyRSS/TestAPI.php

@ -6,6 +6,7 @@
declare(strict_types=1);
namespace JKingWeb\Arsse\TestCase\REST\TinyTinyRSS;
use GuzzleHttp\Exception\ClientException;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\User;
use JKingWeb\Arsse\Database;
@ -785,12 +786,12 @@ LONG_STRING;
];
$out = [
['code' => 1, 'feed_id' => 2],
['code' => 5, 'message' => (new \JKingWeb\Arsse\Feed\Exception("http://example.com/1", new \PicoFeed\Client\UnauthorizedException()))->getMessage()],
['code' => 5, 'message' => (new \JKingWeb\Arsse\Feed\Exception("http://example.com/1", $this->mockGuzzleException(ClientException::class, "", 401)))->getMessage()],
['code' => 1, 'feed_id' => 0],
['code' => 0, 'feed_id' => 3],
['code' => 0, 'feed_id' => 1],
['code' => 3, 'message' => (new \JKingWeb\Arsse\Feed\Exception("http://localhost:8000/Feed/Discovery/Invalid", new \PicoFeed\Reader\SubscriptionNotFoundException()))->getMessage()],
['code' => 2, 'message' => (new \JKingWeb\Arsse\Feed\Exception("http://example.com/6", new \PicoFeed\Client\InvalidUrlException()))->getMessage()],
['code' => 2, 'message' => (new \JKingWeb\Arsse\Feed\Exception("http://example.com/6", $this->mockGuzzleException(ClientException::class, "", 404)))->getMessage()],
['code' => 6, 'message' => (new \JKingWeb\Arsse\Feed\Exception("http://example.com/7", new \PicoFeed\Parser\MalformedXmlException()))->getMessage()],
['code' => 1, 'feed_id' => 4],
['code' => 0, 'feed_id' => 4],
@ -802,12 +803,12 @@ LONG_STRING;
['id' => 4, 'url' => "http://example.com/9"],
];
\Phake::when(Arsse::$db)->subscriptionAdd(...$db[0])->thenReturn(2);
\Phake::when(Arsse::$db)->subscriptionAdd(...$db[1])->thenThrow(new \JKingWeb\Arsse\Feed\Exception("http://example.com/1", new \PicoFeed\Client\UnauthorizedException()));
\Phake::when(Arsse::$db)->subscriptionAdd(...$db[1])->thenThrow(new \JKingWeb\Arsse\Feed\Exception("http://example.com/1", $this->mockGuzzleException(ClientException::class, "", 401)));
\Phake::when(Arsse::$db)->subscriptionAdd(...$db[2])->thenReturn(2);
\Phake::when(Arsse::$db)->subscriptionAdd(...$db[3])->thenThrow(new ExceptionInput("constraintViolation"));
\Phake::when(Arsse::$db)->subscriptionAdd(...$db[4])->thenThrow(new ExceptionInput("constraintViolation"));
\Phake::when(Arsse::$db)->subscriptionAdd(...$db[5])->thenThrow(new ExceptionInput("constraintViolation"));
\Phake::when(Arsse::$db)->subscriptionAdd(...$db[6])->thenThrow(new \JKingWeb\Arsse\Feed\Exception("http://example.com/6", new \PicoFeed\Client\InvalidUrlException()));
\Phake::when(Arsse::$db)->subscriptionAdd(...$db[6])->thenThrow(new \JKingWeb\Arsse\Feed\Exception("http://example.com/6", $this->mockGuzzleException(ClientException::class, "", 404)));
\Phake::when(Arsse::$db)->subscriptionAdd(...$db[7])->thenThrow(new \JKingWeb\Arsse\Feed\Exception("http://example.com/7", new \PicoFeed\Parser\MalformedXmlException()));
\Phake::when(Arsse::$db)->subscriptionAdd(...$db[8])->thenReturn(4);
\Phake::when(Arsse::$db)->subscriptionAdd(...$db[9])->thenThrow(new ExceptionInput("constraintViolation"));

14
tests/lib/AbstractTest.php

@ -6,6 +6,8 @@
declare(strict_types=1);
namespace JKingWeb\Arsse\Test;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use JKingWeb\Arsse\Exception;
use JKingWeb\Arsse\Arsse;
use JKingWeb\Arsse\Conf;
@ -325,4 +327,16 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
$this->assertArraySubset($expected, [], false, "Expectations not in result set.");
}
}
/** Guzzle's exception classes require some fairly complicated construction; this abstracts it all away so that only message and code need be supplied */
protected function mockGuzzleException(string $class, ?string $message = null, ?int $code = null, ?\Throwable $e = null): GuzzleException {
if (is_a($class, RequestException::class, true)) {
$req = \Phake::mock(RequestInterface::class);
$res = \Phake::mock(ResponseInterface::class);
\Phake::when($res)->getStatusCode->thenReturn($code ?? 0);
return new $class($message ?? "", $req, $res, $e);
} else {
return new $class($message ?? "", $code ?? 0, $e);
}
}
}

Loading…
Cancel
Save