From 64ca5f1be08da51e018ace104696dbc0bc543ab2 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Mon, 1 Mar 2021 23:27:58 -0500 Subject: [PATCH] Fix strict comparison failures --- lib/REST/TinyTinyRSS/API.php | 4 ++-- lib/User/Driver.php | 2 -- tests/lib/AbstractTest.php | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/REST/TinyTinyRSS/API.php b/lib/REST/TinyTinyRSS/API.php index 11b983d3..37326230 100644 --- a/lib/REST/TinyTinyRSS/API.php +++ b/lib/REST/TinyTinyRSS/API.php @@ -947,7 +947,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler { throw new Exception("INCORRECT_USAGE"); } try { - Arsse::$db->feedUpdate(Arsse::$db->subscriptionPropertiesGet(Arsse::$user->id, $data['feed_id'])['feed']); + Arsse::$db->feedUpdate((int) Arsse::$db->subscriptionPropertiesGet(Arsse::$user->id, $data['feed_id'])['feed']); } catch (ExceptionInput $e) { throw new Exception("FEED_NOT_FOUND"); } @@ -973,7 +973,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler { // this function doesn't complain about invalid article IDs $article = V::id($data['article_id']) ? $data['article_id'] : 0; try { - $list = $article ? Arsse::$db->articleLabelsGet(Arsse::$user->id, $article) : []; + $list = $article ? Arsse::$db->articleLabelsGet(Arsse::$user->id, (int) $article) : []; } catch (ExceptionInput $e) { $list = []; } diff --git a/lib/User/Driver.php b/lib/User/Driver.php index 87668791..fcf2010f 100644 --- a/lib/User/Driver.php +++ b/lib/User/Driver.php @@ -7,8 +7,6 @@ declare(strict_types=1); namespace JKingWeb\Arsse\User; interface Driver { - public function __construct(); - /** Returns a human-friendly name for the driver (for display in installer, for example) */ public static function driverName(): string; diff --git a/tests/lib/AbstractTest.php b/tests/lib/AbstractTest.php index 5d9eb5e7..3ed6fc4d 100644 --- a/tests/lib/AbstractTest.php +++ b/tests/lib/AbstractTest.php @@ -226,7 +226,7 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { } foreach ($value as $k => $v) { if (is_array($v)) { - $value[$k] = $this->v($v); + $value[$k] = $this->stringify($v); } elseif (is_int($v) || is_float($v)) { $value[$k] = (string) $v; } @@ -324,6 +324,10 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { } public function assertResult(array $expected, Result $data): void { + // stringify our expectations if necessary + if (static::$stringOutput ?? false) { + $expected = $this->stringify($expected); + } $data = $data->getAll(); $this->assertCount(sizeof($expected), $data, "Number of result rows (".sizeof($data).") differs from number of expected rows (".sizeof($expected).")"); if (sizeof($expected)) { @@ -337,12 +341,19 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase { } // filter the result set to contain just the desired keys (we don't care if the result has extra keys) $rows = []; + $keys = array_keys($keys); foreach ($data as $row) { - $rows[] = array_intersect_key($row, $keys); + $r = []; + foreach ($keys as $k) { + if (array_key_exists($k, $row)) { + $r[$k] = $row[$k]; + } + } + $rows[] = $r; } // compare the result set to the expectations foreach ($rows as $row) { - $this->assertEquals($row, $expected, "Result set contains unexpected record."); + $this->assertContains($row, $expected, "Result set contains unexpected record.\n".var_export($expected, true)); $found = array_search($row, $expected); unset($expected[$found]); }