File tree Expand file tree Collapse file tree 2 files changed +46
-11
lines changed Expand file tree Collapse file tree 2 files changed +46
-11
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ namespace Supabase \Client \Util ;
3+ use Dotenv \Dotenv ;
4+
5+ class EnvSetup
6+ {
7+ public static function env ($ path ): array
8+ {
9+ // If the env vars are set and not empty use them
10+ $ key = getenv ('API_KEY ' );
11+ $ url = getenv ('URL ' );
12+
13+ // else check try to load the .env file in the $path
14+ if (empty ($ key ) || empty ($ url )) {
15+ $ loaded = Dotenv::createArrayBacked ($ path )->safeLoad ();
16+
17+ if (key_exists ('API_KEY ' , $ loaded )) {
18+ $ key = $ loaded ['API_KEY ' ];
19+ }
20+
21+ if (key_exists ('URL ' , $ loaded )) {
22+ $ url = $ loaded ['URL ' ];
23+ }
24+ }
25+
26+ if (empty ($ key )) {
27+ throw new \Exception ('Could not load API_KEY ' );
28+ }
29+
30+ if (empty ($ url )) {
31+ throw new \Exception ('Could not load URL ' );
32+ }
33+
34+ return [
35+ 'API_KEY ' => $ key ,
36+ 'URL ' => $ url ,
37+ ];
38+ }
39+ }
Original file line number Diff line number Diff line change 66use PHPUnit \Framework \Attributes \Test ;
77use PHPUnit \Framework \TestCase ;
88use Supabase \Client \Functions as Supabase ;
9- use Dotenv \ Dotenv ;
9+ use Supabase \ Client \ Util \ EnvSetup ;
1010
1111#[CoversClass(Functions::class)]
1212class SupabaseTest extends TestCase
1313{
1414 #[Test]
15- public function connected ()
15+ public function setUp () : void
1616 {
17- $ dotenv = Dotenv::createImmutable (__DIR__ ."/../ " );
18- $ dotenv ->load ();
17+ parent ::setUp ();
18+ $ keys = EnvSetup::env (__DIR__ .'/../ ' );
19+ $ key = $ keys ['API_KEY ' ];
20+ $ url = $ keys ['URL ' ];
1921
20- $ config = [
21- 'url ' => $ _ENV ['URL ' ],
22- 'apikey ' => $ _ENV ['APIKEY ' ]
23- ];
24-
25- $ client = new Supabase ($ config ['url ' ], $ config ['apikey ' ]);
22+ $ client = new Supabase ($ url , $ key );
2623 $ this ->assertInstanceOf (Supabase::class, $ client );
27- // $this->assertTrue($client->getAllData('Users'));
2824 }
2925}
You can’t perform that action at this time.
0 commit comments