@@ -5805,52 +5805,53 @@ public function testInvalidCreatedAndUpdatedAtThrowStructureException(): void
58055805 {
58065806 /** @var Database $database */
58075807 $ database = $ this ->getDatabase ();
5808+
5809+ if (!$ database ->getAdapter ()->getSupportForAttributes ()) {
5810+ $ this ->expectNotToPerformAssertions ();
5811+ return ;
5812+ }
5813+
58085814 $ collection = 'invalid_date_attributes ' ;
58095815
58105816 $ database ->createCollection ($ collection );
58115817 $ this ->assertEquals (true , $ database ->createAttribute ($ collection , 'string ' , Database::VAR_STRING , 128 , false ));
58125818
5813- $ invalidDates = [
5814- 'not-a-date ' ,
5815- '2026-13-01T00:00:00.000+00:00 ' ,
5816- ];
5817-
58185819 $ database ->setPreserveDates (true );
58195820
58205821 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- }
5822+ // Outside allowed year range (Structure uses DatetimeValidator min/max, e.g. 0000–9999).
5823+ $ invalidDate = '10000-01-01T00:00:00.000+00:00 ' ;
58485824
5849- $ this ->fail ('Expected StructureException for invalid ' . $ attribute );
5850- } catch (Throwable $ e ) {
5851- $ this ->assertInstanceOf (StructureException::class, $ e );
5852- }
5853- }
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 );
58545855 }
58555856 } finally {
58565857 $ database ->setPreserveDates (false );
0 commit comments