@@ -215,7 +215,7 @@ public function getSource(): Source
215215 $ _ENV ['SOURCE_APPWRITE_TEST_ENDPOINT ' ],
216216 $ _ENV ['SOURCE_APPWRITE_TEST_KEY ' ],
217217 Appwrite::SOURCE_DATABASE ,
218- $ this ->getDatabase (),
218+ $ this ->getDatabase (' source ' ),
219219 );
220220 case 'supabase ' :
221221 return new Supabase (
@@ -252,7 +252,7 @@ public function getDestination(): Destination
252252 $ _ENV ['DESTINATION_APPWRITE_TEST_PROJECT ' ],
253253 $ _ENV ['DESTINATION_APPWRITE_TEST_ENDPOINT ' ],
254254 $ _ENV ['DESTINATION_APPWRITE_TEST_KEY ' ],
255- $ this ->getDatabase (),
255+ $ this ->getDatabase (' destination ' ),
256256 self ::STRUCTURE
257257 );
258258 case 'local ' :
@@ -262,7 +262,7 @@ public function getDestination(): Destination
262262 }
263263 }
264264
265- public function getDatabase (): Database
265+ public function getDatabase (string $ type ): Database
266266 {
267267 Database::addFilter (
268268 'subQueryAttributes ' ,
@@ -277,12 +277,21 @@ function (mixed $value, Document $document, Database $database) {
277277 ]);
278278
279279 foreach ($ attributes as $ attribute ) {
280- if ($ attribute ->getAttribute ('type ' ) === Database::VAR_RELATIONSHIP ) {
281- $ options = $ attribute ->getAttribute ('options ' );
282- foreach ($ options as $ key => $ value ) {
283- $ attribute ->setAttribute ($ key , $ value );
284- }
285- $ attribute ->removeAttribute ('options ' );
280+ $ attributeType = $ attribute ->getAttribute ('type ' );
281+
282+ switch ($ attributeType ) {
283+ case Database::VAR_RELATIONSHIP :
284+ $ options = $ attribute ->getAttribute ('options ' );
285+ foreach ($ options as $ key => $ value ) {
286+ $ attribute ->setAttribute ($ key , $ value );
287+ }
288+ $ attribute ->removeAttribute ('options ' );
289+ break ;
290+
291+ case Database::VAR_STRING :
292+ $ filters = $ attribute ->getAttribute ('filters ' , []);
293+ $ attribute ->setAttribute ('encrypt ' , in_array ('encrypt ' , $ filters ));
294+ break ;
286295 }
287296 }
288297
@@ -363,10 +372,16 @@ function (mixed $value, Document $attribute) {
363372 }
364373 );
365374
375+ $ prefix = match ($ type ) {
376+ 'source ' => 'SOURCE_APPWRITE_TEST_ ' ,
377+ 'destination ' => 'DESTINATION_APPWRITE_TEST_ ' ,
378+ default => throw new Exception ('Invalid type for database ' ),
379+ };
380+
366381 $ database = new Database (new MariaDB (new PDO (
367- $ _ENV [' DESTINATION_APPWRITE_TEST_DSN ' ],
368- $ _ENV [' DESTINATION_APPWRITE_TEST_USER ' ],
369- $ _ENV [' DESTINATION_APPWRITE_TEST_PASSWORD ' ],
382+ $ _ENV [$ prefix . ' DSN ' ],
383+ $ _ENV [$ prefix . ' USER ' ],
384+ $ _ENV [$ prefix . ' PASSWORD ' ],
370385 [
371386 PDO ::ATTR_TIMEOUT => 3 ,
372387 PDO ::ATTR_PERSISTENT => true ,
@@ -378,7 +393,7 @@ function (mixed $value, Document $attribute) {
378393
379394 $ database
380395 ->setDatabase ('appwrite ' )
381- ->setNamespace ('_ ' . $ _ENV [' DESTINATION_APPWRITE_TEST_NAMESPACE ' ]);
396+ ->setNamespace ('_ ' . $ _ENV [$ prefix . ' NAMESPACE ' ]);
382397
383398 return $ database ;
384399 }
0 commit comments