Skip to content

Commit cf11809

Browse files
committed
Add setPreserveSequence to Mirror and test invalid sequence validation
- Add setPreserveSequence delegation to Mirror.php - Add test case for invalid $sequence value throwing StructureException
1 parent b0586bd commit cf11809

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Database/Mirror.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ public function setPreserveDates(bool $preserve): static
139139
return $this;
140140
}
141141

142+
public function setPreserveSequence(bool $preserve): static
143+
{
144+
$this->delegate(__FUNCTION__, \func_get_args());
145+
146+
$this->preserveSequence = $preserve;
147+
148+
return $this;
149+
}
150+
142151
public function enableValidation(): static
143152
{
144153
$this->delegate(__FUNCTION__);

tests/e2e/Adapter/Scopes/DocumentTests.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,32 @@ public function testPreserveSequenceUpsert(): void
12861286
// Verify flag was reset after withPreserveSequence
12871287
$this->assertFalse($database->getPreserveSequence());
12881288

1289+
// Test: With preserveSequence=true, invalid $sequence should throw error (SQL adapters only)
1290+
$database->setPreserveSequence(true);
1291+
1292+
try {
1293+
$database->upsertDocuments($collectionName, [
1294+
new Document([
1295+
'$id' => 'doc1',
1296+
'$sequence' => 'abc', // Invalid sequence value
1297+
'$permissions' => [
1298+
Permission::read(Role::any()),
1299+
Permission::update(Role::any()),
1300+
],
1301+
'name' => 'Alice Invalid',
1302+
]),
1303+
]);
1304+
// Schemaless adapters may not validate sequence type, so only fail for schemaful
1305+
if ($database->getAdapter()->getSupportForAttributes()) {
1306+
$this->fail('Expected StructureException for invalid sequence');
1307+
}
1308+
} catch (Throwable $e) {
1309+
if ($database->getAdapter()->getSupportForAttributes()) {
1310+
$this->assertInstanceOf(StructureException::class, $e);
1311+
$this->assertStringContainsString('sequence', $e->getMessage());
1312+
}
1313+
}
1314+
12891315
$database->setPreserveSequence(false);
12901316
$database->deleteCollection($collectionName);
12911317
}

0 commit comments

Comments
 (0)