File tree Expand file tree Collapse file tree 8 files changed +64
-33
lines changed Expand file tree Collapse file tree 8 files changed +64
-33
lines changed Original file line number Diff line number Diff line change 1- # Supabase Config
2-
3- # Supabase database URL
4- SB_URL = https://[your].supabase.co
5-
6- # Supabase Anon or `service_role` API key.
7- SB_APIKEY = your anon api key
1+ URL =
2+ API_KEY =
Original file line number Diff line number Diff line change 2121 "license" : " MIT" ,
2222 "autoload" : {
2323 "psr-4" : {
24- "Supabase\\ Client \\ " : " src/"
24+ "Supabase\\ " : " src/"
2525 }
2626 },
2727 "autoload-dev" : {
5555 "post-root-package-install" : [
5656 " @php -r \" file_exists('.env') || copy('.env.example', '.env');\" "
5757 ],
58- "unit" : " phpunit" ,
59- "types " : " phpstan analyse --ansi" ,
58+ "test: unit" : " phpunit" ,
59+ "test:type " : " phpstan analyse --ansi" ,
6060 "test" : [
61- " @unit"
61+ " @test:unit" ,
62+ " @test:type"
6263 ]
6364 },
6465 "minimum-stability" : " dev" ,
Original file line number Diff line number Diff line change @@ -2,6 +2,5 @@ parameters:
22 level: max
33 paths:
44 - src
5- - tests
65
76 reportUnmatchedIgnoredErrors: true
Original file line number Diff line number Diff line change 1- <?php
2- declare (strict_types= 1 );
3- namespace Supabase \ Client ;
1+ <?php declare (strict_types= 1 );
2+
3+ namespace Supabase ;
44
55class Exceptions extends Exception {
66 public static function Error ()
Original file line number Diff line number Diff line change 1- <?php
2- declare (strict_types=1 );
1+ <?php declare (strict_types=1 );
32
4- namespace Supabase \Client ;
5- use Supabase \Client \Supabase ;
3+ namespace Supabase ;
4+
5+ use Supabase \Supabase ;
66
77class Functions extends Supabase
88{
Original file line number Diff line number Diff line change 11<?php
22declare (strict_types=1 );
33
4- namespace Supabase \ Client ;
4+ namespace Supabase ;
55use Exception ;
66
77class Supabase
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace Supabase \Util ;
3+
4+ use Dotenv \Dotenv ;
5+
6+ class EnvSetup
7+ {
8+ public static function env ($ path ): array
9+ {
10+ // If the env vars are set and not empty use them
11+ $ key = getenv ('API_KEY ' );
12+ $ url = getenv ('URL ' );
13+
14+ // else check try to load the .env file in the $path
15+ if (empty ($ key ) || empty ($ url )) {
16+ $ loaded = Dotenv::createArrayBacked ($ path )->safeLoad ();
17+
18+ if (key_exists ('API_KEY ' , $ loaded )) {
19+ $ key = $ loaded ['API_KEY ' ];
20+ }
21+
22+ if (key_exists ('URL ' , $ loaded )) {
23+ $ url = $ loaded ['URL ' ];
24+ }
25+ }
26+
27+ if (empty ($ key )) {
28+ throw new \Exception ('Could not load API_KEY ' );
29+ }
30+
31+ if (empty ($ url )) {
32+ throw new \Exception ('Could not load URL ' );
33+ }
34+
35+ return [
36+ 'API_KEY ' => $ key ,
37+ 'URL ' => $ url ,
38+ ];
39+ }
40+ }
Original file line number Diff line number Diff line change 55use PHPUnit \Framework \Attributes \CoversClass ;
66use PHPUnit \Framework \Attributes \Test ;
77use PHPUnit \Framework \TestCase ;
8- use Supabase \Client \ Functions as Supabase ;
9- use Dotenv \ Dotenv ;
8+ use Supabase \Functions as Supabase ;
9+ use Supabase \ Util \ EnvSetup ;
1010
11- #[CoversClass(Functions ::class)]
11+ #[CoversClass(Supabase ::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 ->safeLoad ();
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