Skip to content

Commit 33f35f5

Browse files
authored
Merge pull request #650 from utopia-php/get-sequence-default
Cahnge getSequence default for null
2 parents eaa4e27 + 7a9bedb commit 33f35f5

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/Database/Document.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,17 @@ public function getId(): string
6666
}
6767

6868
/**
69-
* @return string
69+
* @return string|null
7070
*/
71-
public function getSequence(): string
71+
public function getSequence(): ?string
7272
{
73-
return $this->getAttribute('$sequence', '');
73+
$sequence = $this->getAttribute('$sequence');
74+
75+
if ($sequence === null) {
76+
return null;
77+
}
78+
79+
return $sequence;
7480
}
7581

7682
/**
@@ -172,10 +178,12 @@ public function getUpdatedAt(): ?string
172178
public function getTenant(): ?int
173179
{
174180
$tenant = $this->getAttribute('$tenant');
175-
if ($tenant !== null) {
176-
return (int)$tenant;
181+
182+
if ($tenant === null) {
183+
return null;
177184
}
178-
return null;
185+
186+
return (int) $tenant;
179187
}
180188

181189
/**

tests/e2e/Adapter/Scopes/DocumentTests.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,9 +1968,6 @@ public function testFindByInternalID(array $data): void
19681968
]);
19691969

19701970
$this->assertEquals(1, count($documents));
1971-
1972-
$empty = new Document();
1973-
$this->assertEquals('', $empty->getSequence());
19741971
}
19751972

19761973
public function testFindOrderBy(): void

tests/unit/DocumentTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,12 @@ public function testGetArrayCopy(): void
409409
], $this->document->getArrayCopy());
410410
$this->assertEquals([], $this->empty->getArrayCopy());
411411
}
412+
413+
public function testEmptyDocumentSequence(): void
414+
{
415+
$empty = new Document();
416+
417+
$this->assertNull($empty->getSequence());
418+
$this->assertNotSame('', $empty->getSequence());
419+
}
412420
}

0 commit comments

Comments
 (0)