From aed3749da8d91367d6dd62b6a609eee355ef6526 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Tue, 9 Jul 2024 14:58:31 -0400 Subject: [PATCH] Shore up coverage --- lib/Feed/Exception.php | 3 ++- tests/cases/Misc/TestValueInfo.php | 4 ++++ tests/cases/REST/Miniflux/TestV1.php | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Feed/Exception.php b/lib/Feed/Exception.php index 069bed9e..979c0567 100644 --- a/lib/Feed/Exception.php +++ b/lib/Feed/Exception.php @@ -31,7 +31,8 @@ class Exception extends \JKingWeb\Arsse\AbstractException { } elseif (preg_match("/^cURL error (\d+):/", $msg, $match)) { $msgID = self::CURL_ERROR_MAP[(int) $match[1]] ?? "internalError"; } else { - $msgID = "internalError"; + // Fallback for future Guzzle exceptions we may not know about + $msgID = "internalError"; // @codeCoverageIgnore } } elseif ($e instanceof PicoFeedException) { $className = get_class($e); diff --git a/tests/cases/Misc/TestValueInfo.php b/tests/cases/Misc/TestValueInfo.php index 9f0e8223..ed03d34c 100644 --- a/tests/cases/Misc/TestValueInfo.php +++ b/tests/cases/Misc/TestValueInfo.php @@ -315,6 +315,9 @@ class TestValueInfo extends \JKingWeb\Arsse\Test\AbstractTest { $this->assertNan($act, $msg); } elseif (is_scalar($exp)) { $this->assertSame($exp, $act, $msg); + } elseif ($exp instanceof \DateInterval && $act instanceof \DateInterval) { + $format = "\Py\Ym\Md\D\Th\HiMs\S"; + $this->assertSame($exp->format($format), $act->format($format), $msg); } else { $this->assertEquals($exp, $act, $msg); } @@ -532,6 +535,7 @@ class TestValueInfo extends \JKingWeb\Arsse\Test\AbstractTest { [$this->i("P2DT1H"), [null,true], [true, false], [(48 + 1) * 60 * 60, false], [1.0 * (48 + 1) * 60 * 60, false], ["P2DT1H", true], [[$this->i("P2DT1H")], false], [$this->i("P2DT1H"), true]], [$this->i("PT0H"), [null,true], [true, false], [0, false], [0.0, false], ["PT0S", true], [[$this->i("PT0H")], false], [$this->i("PT0H"), true]], [$dateDiff, [null,true], [true, false], [366 * 24 * 60 * 60, false], [1.0 * 366 * 24 * 60 * 60, false], ["P366D", true], [[$dateDiff], false], [$dateNorm, true]], + ["1 year, 2 days", [null,true], [true, false], [0, false], [0.0, false], ["1 year, 2 days", true], [["1 year, 2 days"], false], [$this->i("P1Y2D"), false]], ["P1Y2D", [null,true], [true, false], [0, false], [0.0, false], ["P1Y2D", true], [["P1Y2D"], false], [$this->i("P1Y2D"), true]], ] as $set) { // shift the input value off the set diff --git a/tests/cases/REST/Miniflux/TestV1.php b/tests/cases/REST/Miniflux/TestV1.php index 3c31009d..288e9f4c 100644 --- a/tests/cases/REST/Miniflux/TestV1.php +++ b/tests/cases/REST/Miniflux/TestV1.php @@ -169,6 +169,11 @@ class TestV1 extends \JKingWeb\Arsse\Test\AbstractTest { ]; } + public function testRejectMalformedData(): void { + $exp = V1::respError(["InvalidBodyJSON", "Syntax error"], 400); + $this->assertMessage($exp, $this->req("POST", "/discover", "{")); + } + public function testRejectBadlyTypedData(): void { $exp = V1::respError(["InvalidInputType", 'field' => "url", 'expected' => "string", 'actual' => "integer"], 422); $this->assertMessage($exp, $this->req("POST", "/discover", ['url' => 2112]));