@@ -5801,6 +5801,63 @@ 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+ $ collection = 'invalid_date_attributes ' ;
5809+
5810+ $ database ->createCollection ($ collection );
5811+ $ this ->assertEquals (true , $ database ->createAttribute ($ collection , 'string ' , Database::VAR_STRING , 128 , false ));
5812+
5813+ $ invalidDates = [
5814+ 'not-a-date ' ,
5815+ '2026-13-01T00:00:00.000+00:00 ' ,
5816+ ];
5817+
5818+ $ database ->setPreserveDates (true );
5819+
5820+ try {
5821+ foreach ($ invalidDates as $ index => $ invalidDate ) {
5822+ foreach (['$createdAt ' , '$updatedAt ' ] as $ attribute ) {
5823+ try {
5824+ if ($ attribute === '$createdAt ' ) {
5825+ $ database ->createDocument ($ collection , new Document ([
5826+ '$id ' => $ attribute . '- ' . $ index ,
5827+ '$permissions ' => [
5828+ Permission::read (Role::any ()),
5829+ Permission::write (Role::any ()),
5830+ Permission::update (Role::any ()),
5831+ ],
5832+ 'string ' => 'invalid-date ' ,
5833+ $ attribute => $ invalidDate ,
5834+ ]));
5835+ } else {
5836+ $ document = $ database ->createDocument ($ collection , new Document ([
5837+ '$id ' => 'doc- ' . $ index ,
5838+ '$permissions ' => [
5839+ Permission::read (Role::any ()),
5840+ Permission::write (Role::any ()),
5841+ Permission::update (Role::any ()),
5842+ ],
5843+ 'string ' => 'valid-date ' ,
5844+ ]));
5845+ $ document ->setAttribute ($ attribute , $ invalidDate );
5846+ $ database ->updateDocument ($ collection , $ document ->getId (), $ document );
5847+ }
5848+
5849+ $ this ->fail ('Expected StructureException for invalid ' . $ attribute );
5850+ } catch (Throwable $ e ) {
5851+ $ this ->assertInstanceOf (StructureException::class, $ e );
5852+ }
5853+ }
5854+ }
5855+ } finally {
5856+ $ database ->setPreserveDates (false );
5857+ $ database ->deleteCollection ($ collection );
5858+ }
5859+ }
5860+
58045861 public function testSingleDocumentDateOperations (): void
58055862 {
58065863 /** @var Database $database */
0 commit comments