Przeglądaj źródła

Fix TypeError from entry IDs on 32-bit platforms (#9578)

An integer literal above PHP_INT_MAX is a float on x86, and _id() only
accepted int|string, so the export test failed there with "must be of type
string|int, float given".

* Build entry IDs as strings in the tests

1700000000000000 + $i is a float on 32-bit platforms, where it exceeds
PHP_INT_MAX, and FreshRSS_Entry::_id() rejects it. Entry IDs are strings
everywhere else, since uTimeString() and the DAO layer both produce
numeric strings, so keep the ID a string in the test instead of accepting
a float. A test now pins that contract.

Refs #9569

---------

Co-authored-by: Raed <Raed2180416@users.noreply.github.com>
Raed 7 godzin temu
rodzic
commit
60e477423f

+ 8 - 0
tests/app/Models/EntryTest.php

@@ -109,4 +109,12 @@ final class EntryTest extends \PHPUnit\Framework\TestCase {
 		self::assertSame('A &amp; B', $item['title']);
 		self::assertSame('B &amp; C', $item['author']);
 	}
+
+	/** Above PHP_INT_MAX, an integer literal is a float on 32-bit platforms, so an entry ID is only ever a string */
+	public function test_idRejectsAFloat(): void {
+		$entry = new FreshRSS_Entry(1, 'guid-1', 'Title', '', '', 'https://example.net/1', 1700000000);
+		$this->expectException(\TypeError::class);
+		// @phpstan-ignore argument.type
+		$entry->_id(1700000000000001.0);
+	}
 }

+ 2 - 1
tests/app/Views/exportArticlesTest.php

@@ -28,7 +28,8 @@ final class exportArticlesTest extends \PHPUnit\Framework\TestCase {
 		for ($i = 1; $i <= $count; $i++) {
 			$entry = new FreshRSS_Entry(1, 'guid-' . $i, 'Title ' . $i, '', str_repeat('<p>Contenu exporté ' . $i . '</p>', 200),
 				'https://example.net/' . $i, 1700000000 + $i);
-			$entry->_id(1700000000000000 + $i);
+			// A string, because this value exceeds PHP_INT_MAX on 32-bit platforms and would be a float there
+			$entry->_id('17000000000000' . sprintf('%02d', $i));	// @phpstan-ignore argument.type (numeric-string)
 			$entries[] = $entry;
 		}
 		return $entries;