File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff 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__ );
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments