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

Fix strict comparison failures

This commit is contained in:
J. King 2021-03-01 23:27:58 -05:00
parent ed285ee28b
commit 64ca5f1be0
3 changed files with 16 additions and 7 deletions

View file

@ -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 = [];
}

View file

@ -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;

View file

@ -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]);
}