@@ -5801,6 +5801,64 @@ public function testDateTimeDocument(): void
58015801 $ database ->deleteCollection ($ collection );
58025802 }
58035803
5804+ public function testInvalidCreatedAndUpdatedAtThrowStructureException (): void
5805+ {
5806+ /** @var Database $database */
5807+ $ database = $ this ->getDatabase ();
5808+
5809+ if (!$ database ->getAdapter ()->getSupportForAttributes ()) {
5810+ $ this ->expectNotToPerformAssertions ();
5811+ return ;
5812+ }
5813+
5814+ $ collection = 'invalid_date_attributes ' ;
5815+
5816+ $ database ->createCollection ($ collection );
5817+ $ this ->assertEquals (true , $ database ->createAttribute ($ collection , 'string ' , Database::VAR_STRING , 128 , false ));
5818+
5819+ $ database ->setPreserveDates (true );
5820+
5821+ try {
5822+ // Outside allowed year range (Structure uses DatetimeValidator min/max, e.g. 0000–9999).
5823+ $ invalidDate = '10000-01-01T00:00:00.000+00:00 ' ;
5824+
5825+ try {
5826+ $ database ->createDocument ($ collection , new Document ([
5827+ '$id ' => 'doc1 ' ,
5828+ '$permissions ' => [
5829+ Permission::read (Role::any ()),
5830+ Permission::update (Role::any ()),
5831+ ],
5832+ '$createdAt ' => $ invalidDate ,
5833+ ]));
5834+ $ this ->fail ('Expected StructureException for invalid $createdAt ' );
5835+ } catch (Throwable $ e ) {
5836+ $ this ->assertInstanceOf (StructureException::class, $ e );
5837+ }
5838+
5839+ $ database ->createDocument ($ collection , new Document ([
5840+ '$id ' => 'doc2 ' ,
5841+ '$permissions ' => [
5842+ Permission::read (Role::any ()),
5843+ Permission::update (Role::any ()),
5844+ ],
5845+ 'string ' => 'x ' ,
5846+ ]));
5847+
5848+ try {
5849+ $ database ->updateDocument ($ collection , 'doc2 ' , new Document ([
5850+ '$updatedAt ' => $ invalidDate ,
5851+ ]));
5852+ $ this ->fail ('Expected StructureException for invalid $updatedAt ' );
5853+ } catch (Throwable $ e ) {
5854+ $ this ->assertInstanceOf (StructureException::class, $ e );
5855+ }
5856+ } finally {
5857+ $ database ->setPreserveDates (false );
5858+ $ database ->deleteCollection ($ collection );
5859+ }
5860+ }
5861+
58045862 public function testSingleDocumentDateOperations (): void
58055863 {
58065864 /** @var Database $database */
0 commit comments