@@ -25,7 +25,10 @@ trait GeneralTests
2525{
2626 public function testPing (): void
2727 {
28- $ this ->assertEquals (true , static ::getDatabase ()->ping ());
28+ /** @var Database $database */
29+ $ database = static ::getDatabase ();
30+
31+ $ this ->assertEquals (true , $ database ->ping ());
2932 }
3033
3134 /**
@@ -43,11 +46,14 @@ public function testQueryTimeout(): void
4346 return ;
4447 }
4548
46- static ::getDatabase ()->createCollection ('global-timeouts ' );
49+ /** @var Database $database */
50+ $ database = static ::getDatabase ();
51+
52+ $ database ->createCollection ('global-timeouts ' );
4753
4854 $ this ->assertEquals (
4955 true ,
50- static :: getDatabase () ->createAttribute (
56+ $ database ->createAttribute (
5157 collection: 'global-timeouts ' ,
5258 id: 'longtext ' ,
5359 type: Database::VAR_STRING ,
@@ -57,7 +63,7 @@ public function testQueryTimeout(): void
5763 );
5864
5965 for ($ i = 0 ; $ i < 20 ; $ i ++) {
60- static :: getDatabase () ->createDocument ('global-timeouts ' , new Document ([
66+ $ database ->createDocument ('global-timeouts ' , new Document ([
6167 'longtext ' => file_get_contents (__DIR__ . '/../../../resources/longtext.txt ' ),
6268 '$permissions ' => [
6369 Permission::read (Role::any ()),
@@ -67,16 +73,16 @@ public function testQueryTimeout(): void
6773 ]));
6874 }
6975
70- static :: getDatabase () ->setTimeout (1 );
76+ $ database ->setTimeout (1 );
7177
7278 try {
73- static :: getDatabase () ->find ('global-timeouts ' , [
79+ $ database ->find ('global-timeouts ' , [
7480 Query::notEqual ('longtext ' , 'appwrite ' ),
7581 ]);
7682 $ this ->fail ('Failed to throw exception ' );
7783 } catch (\Exception $ e ) {
78- static :: getDatabase () ->clearTimeout ();
79- static :: getDatabase () ->deleteCollection ('global-timeouts ' );
84+ $ database ->clearTimeout ();
85+ $ database ->deleteCollection ('global-timeouts ' );
8086 $ this ->assertInstanceOf (TimeoutException::class, $ e );
8187 }
8288 }
@@ -87,25 +93,28 @@ public function testPreserveDatesUpdate(): void
8793 {
8894 Authorization::disable ();
8995
90- static ::getDatabase ()->setPreserveDates (true );
96+ /** @var Database $database */
97+ $ database = static ::getDatabase ();
98+
99+ $ database ->setPreserveDates (true );
91100
92- static :: getDatabase () ->createCollection ('preserve_update_dates ' );
101+ $ database ->createCollection ('preserve_update_dates ' );
93102
94- static :: getDatabase () ->createAttribute ('preserve_update_dates ' , 'attr1 ' , Database::VAR_STRING , 10 , false );
103+ $ database ->createAttribute ('preserve_update_dates ' , 'attr1 ' , Database::VAR_STRING , 10 , false );
95104
96- $ doc1 = static :: getDatabase () ->createDocument ('preserve_update_dates ' , new Document ([
105+ $ doc1 = $ database ->createDocument ('preserve_update_dates ' , new Document ([
97106 '$id ' => 'doc1 ' ,
98107 '$permissions ' => [],
99108 'attr1 ' => 'value1 ' ,
100109 ]));
101110
102- $ doc2 = static :: getDatabase () ->createDocument ('preserve_update_dates ' , new Document ([
111+ $ doc2 = $ database ->createDocument ('preserve_update_dates ' , new Document ([
103112 '$id ' => 'doc2 ' ,
104113 '$permissions ' => [],
105114 'attr1 ' => 'value2 ' ,
106115 ]));
107116
108- $ doc3 = static :: getDatabase () ->createDocument ('preserve_update_dates ' , new Document ([
117+ $ doc3 = $ database ->createDocument ('preserve_update_dates ' , new Document ([
109118 '$id ' => 'doc3 ' ,
110119 '$permissions ' => [],
111120 'attr1 ' => 'value3 ' ,
@@ -114,9 +123,9 @@ public function testPreserveDatesUpdate(): void
114123 $ newDate = '2000-01-01T10:00:00.000+00:00 ' ;
115124
116125 $ doc1 ->setAttribute ('$updatedAt ' , $ newDate );
117- $ doc1 = static :: getDatabase () ->updateDocument ('preserve_update_dates ' , 'doc1 ' , $ doc1 );
126+ $ doc1 = $ database ->updateDocument ('preserve_update_dates ' , 'doc1 ' , $ doc1 );
118127 $ this ->assertEquals ($ newDate , $ doc1 ->getAttribute ('$updatedAt ' ));
119- $ doc1 = static :: getDatabase () ->getDocument ('preserve_update_dates ' , 'doc1 ' );
128+ $ doc1 = $ database ->getDocument ('preserve_update_dates ' , 'doc1 ' );
120129 $ this ->assertEquals ($ newDate , $ doc1 ->getAttribute ('$updatedAt ' ));
121130
122131 $ this ->getDatabase ()->updateDocuments (
@@ -132,14 +141,14 @@ public function testPreserveDatesUpdate(): void
132141 ]
133142 );
134143
135- $ doc2 = static :: getDatabase () ->getDocument ('preserve_update_dates ' , 'doc2 ' );
136- $ doc3 = static :: getDatabase () ->getDocument ('preserve_update_dates ' , 'doc3 ' );
144+ $ doc2 = $ database ->getDocument ('preserve_update_dates ' , 'doc2 ' );
145+ $ doc3 = $ database ->getDocument ('preserve_update_dates ' , 'doc3 ' );
137146 $ this ->assertEquals ($ newDate , $ doc2 ->getAttribute ('$updatedAt ' ));
138147 $ this ->assertEquals ($ newDate , $ doc3 ->getAttribute ('$updatedAt ' ));
139148
140- static :: getDatabase () ->deleteCollection ('preserve_update_dates ' );
149+ $ database ->deleteCollection ('preserve_update_dates ' );
141150
142- static :: getDatabase () ->setPreserveDates (false );
151+ $ database ->setPreserveDates (false );
143152
144153 Authorization::reset ();
145154 }
@@ -148,22 +157,25 @@ public function testPreserveDatesCreate(): void
148157 {
149158 Authorization::disable ();
150159
151- static ::getDatabase ()->setPreserveDates (true );
160+ /** @var Database $database */
161+ $ database = static ::getDatabase ();
152162
153- static :: getDatabase ()-> createCollection ( ' preserve_create_dates ' );
163+ $ database -> setPreserveDates ( true );
154164
155- static ::getDatabase ()->createAttribute ('preserve_create_dates ' , 'attr1 ' , Database::VAR_STRING , 10 , false );
165+ $ database ->createCollection ('preserve_create_dates ' );
166+
167+ $ database ->createAttribute ('preserve_create_dates ' , 'attr1 ' , Database::VAR_STRING , 10 , false );
156168
157169 $ date = '2000-01-01T10:00:00.000+00:00 ' ;
158170
159- static :: getDatabase () ->createDocument ('preserve_create_dates ' , new Document ([
171+ $ database ->createDocument ('preserve_create_dates ' , new Document ([
160172 '$id ' => 'doc1 ' ,
161173 '$permissions ' => [],
162174 'attr1 ' => 'value1 ' ,
163175 '$createdAt ' => $ date
164176 ]));
165177
166- static :: getDatabase () ->createDocuments ('preserve_create_dates ' , [
178+ $ database ->createDocuments ('preserve_create_dates ' , [
167179 new Document ([
168180 '$id ' => 'doc2 ' ,
169181 '$permissions ' => [],
@@ -178,16 +190,16 @@ public function testPreserveDatesCreate(): void
178190 ]),
179191 ], batchSize: 2 );
180192
181- $ doc1 = static :: getDatabase () ->getDocument ('preserve_create_dates ' , 'doc1 ' );
182- $ doc2 = static :: getDatabase () ->getDocument ('preserve_create_dates ' , 'doc2 ' );
183- $ doc3 = static :: getDatabase () ->getDocument ('preserve_create_dates ' , 'doc3 ' );
193+ $ doc1 = $ database ->getDocument ('preserve_create_dates ' , 'doc1 ' );
194+ $ doc2 = $ database ->getDocument ('preserve_create_dates ' , 'doc2 ' );
195+ $ doc3 = $ database ->getDocument ('preserve_create_dates ' , 'doc3 ' );
184196 $ this ->assertEquals ($ date , $ doc1 ->getAttribute ('$createdAt ' ));
185197 $ this ->assertEquals ($ date , $ doc2 ->getAttribute ('$createdAt ' ));
186198 $ this ->assertEquals ($ date , $ doc3 ->getAttribute ('$createdAt ' ));
187199
188- static :: getDatabase () ->deleteCollection ('preserve_create_dates ' );
200+ $ database ->deleteCollection ('preserve_create_dates ' );
189201
190- static :: getDatabase () ->setPreserveDates (false );
202+ $ database ->setPreserveDates (false );
191203
192204 Authorization::reset ();
193205 }
@@ -271,7 +283,11 @@ public function testFindOrderByAfterException(): void
271283 ]);
272284
273285 $ this ->expectException (Exception::class);
274- static ::getDatabase ()->find ('movies ' , [
286+
287+ /** @var Database $database */
288+ $ database = static ::getDatabase ();
289+
290+ $ database ->find ('movies ' , [
275291 Query::limit (2 ),
276292 Query::offset (0 ),
277293 Query::cursorAfter ($ document )
@@ -405,7 +421,7 @@ public function testSharedTablesTenantPerDocument(): void
405421 $ this ->assertEquals (1 , \count ($ docs ));
406422 $ this ->assertEquals ($ doc1Id , $ docs [0 ]->getId ());
407423
408- if (static :: getDatabase () ->getAdapter ()->getSupportForUpserts ()) {
424+ if ($ database ->getAdapter ()->getSupportForUpserts ()) {
409425 // Test upsert with tenant per doc
410426 $ doc3Id = ID ::unique ();
411427 $ database
@@ -521,7 +537,10 @@ public function testSharedTablesTenantPerDocument(): void
521537
522538 public function testCacheFallback (): void
523539 {
524- if (!static ::getDatabase ()->getAdapter ()->getSupportForCacheSkipOnFailure ()) {
540+ /** @var Database $database */
541+ $ database = static ::getDatabase ();
542+
543+ if (!$ database ->getAdapter ()->getSupportForCacheSkipOnFailure ()) {
525544 $ this ->expectNotToPerformAssertions ();
526545 return ;
527546 }
0 commit comments