diff --git a/src/Database/Document.php b/src/Database/Document.php index 566a37444..e8a7a3a08 100644 --- a/src/Database/Document.php +++ b/src/Database/Document.php @@ -66,11 +66,17 @@ public function getId(): string } /** - * @return string + * @return string|null */ - public function getSequence(): string + public function getSequence(): ?string { - return $this->getAttribute('$sequence', ''); + $sequence = $this->getAttribute('$sequence'); + + if ($sequence === null) { + return null; + } + + return $sequence; } /** @@ -172,10 +178,12 @@ public function getUpdatedAt(): ?string public function getTenant(): ?int { $tenant = $this->getAttribute('$tenant'); - if ($tenant !== null) { - return (int)$tenant; + + if ($tenant === null) { + return null; } - return null; + + return (int) $tenant; } /** diff --git a/tests/e2e/Adapter/Scopes/DocumentTests.php b/tests/e2e/Adapter/Scopes/DocumentTests.php index 82b8e026c..188872a3b 100644 --- a/tests/e2e/Adapter/Scopes/DocumentTests.php +++ b/tests/e2e/Adapter/Scopes/DocumentTests.php @@ -1968,9 +1968,6 @@ public function testFindByInternalID(array $data): void ]); $this->assertEquals(1, count($documents)); - - $empty = new Document(); - $this->assertEquals('', $empty->getSequence()); } public function testFindOrderBy(): void diff --git a/tests/unit/DocumentTest.php b/tests/unit/DocumentTest.php index a9ca44e1e..9a41ab534 100644 --- a/tests/unit/DocumentTest.php +++ b/tests/unit/DocumentTest.php @@ -409,4 +409,12 @@ public function testGetArrayCopy(): void ], $this->document->getArrayCopy()); $this->assertEquals([], $this->empty->getArrayCopy()); } + + public function testEmptyDocumentSequence(): void + { + $empty = new Document(); + + $this->assertNull($empty->getSequence()); + $this->assertNotSame('', $empty->getSequence()); + } }