From a10ecbb1cdfdf6dd8ab3c1884b09d9ba987b7ff5 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 8 Jun 2024 12:57:13 -0400 Subject: [PATCH] Pass integer IDs as-is --- src/Parameters.php | 2 +- tests/integration/sqlite/FindTest.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Parameters.php b/src/Parameters.php index 2e13830..e6dffad 100644 --- a/src/Parameters.php +++ b/src/Parameters.php @@ -15,7 +15,7 @@ class Parameters */ public static function id(mixed $key): array { - return [':id' => is_string($key) ? $key : "$key"]; + return [':id' => is_int($key) || is_string($key) ? $key : "$key"]; } /** diff --git a/tests/integration/sqlite/FindTest.php b/tests/integration/sqlite/FindTest.php index 7552a51..c3b7ced 100644 --- a/tests/integration/sqlite/FindTest.php +++ b/tests/integration/sqlite/FindTest.php @@ -2,7 +2,7 @@ namespace Test\Integration\SQLite; -use BitBadger\PDODocument\{Custom, Field, Find}; +use BitBadger\PDODocument\{Custom, Document, Field, Find}; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; use Test\Integration\TestDocument; @@ -53,6 +53,15 @@ class FindTest extends TestCase $this->assertEquals('two', $doc->id, 'An incorrect document was returned'); } + #[TestDox('By ID succeeds when a document is found with numeric ID')] + public function testByIdSucceedsWhenADocumentIsFoundWithNumericId(): void + { + Document::insert(ThrowawayDb::TABLE, ['id' => 18, 'value' => 'howdy']); + $doc = Find::byId(ThrowawayDb::TABLE, 18, TestDocument::class); + $this->assertNotFalse($doc, 'There should have been a document returned'); + $this->assertEquals('18', $doc->id, 'An incorrect document was returned'); + } + #[TestDox('By ID succeeds when a document is not found')] public function testByIdSucceedsWhenADocumentIsNotFound(): void {