Pass integer IDs as-is

This commit is contained in:
Daniel J. Summers 2024-06-08 12:57:13 -04:00
parent 2d8f8b6e87
commit a10ecbb1cd
2 changed files with 11 additions and 2 deletions

View File

@ -15,7 +15,7 @@ class Parameters
*/ */
public static function id(mixed $key): array public static function id(mixed $key): array
{ {
return [':id' => is_string($key) ? $key : "$key"]; return [':id' => is_int($key) || is_string($key) ? $key : "$key"];
} }
/** /**

View File

@ -2,7 +2,7 @@
namespace Test\Integration\SQLite; 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\Attributes\TestDox;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Test\Integration\TestDocument; use Test\Integration\TestDocument;
@ -53,6 +53,15 @@ class FindTest extends TestCase
$this->assertEquals('two', $doc->id, 'An incorrect document was returned'); $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')] #[TestDox('By ID succeeds when a document is not found')]
public function testByIdSucceedsWhenADocumentIsNotFound(): void public function testByIdSucceedsWhenADocumentIsNotFound(): void
{ {