Skip to content

Commit 59a99d0

Browse files
Code with sushil patch 1 (Ashishkumbhar01#61)
* update * .env file load setup * .env file load setup update * .env file load setup update * Rename .env.example to .env * Update .env * .env.example * composer psr-4 update * update * update * Delete .env
1 parent 1492a62 commit 59a99d0

File tree

8 files changed

+64
-33
lines changed

8 files changed

+64
-33
lines changed

.env.example

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
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=

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"license": "MIT",
2222
"autoload": {
2323
"psr-4": {
24-
"Supabase\\Client\\": "src/"
24+
"Supabase\\": "src/"
2525
}
2626
},
2727
"autoload-dev": {
@@ -55,10 +55,11 @@
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",

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ parameters:
22
level: max
33
paths:
44
- src
5-
- tests
65

76
reportUnmatchedIgnoredErrors: true

src/Exceptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?php
2-
declare(strict_types=1);
3-
namespace Supabase\Client;
1+
<?php declare(strict_types=1);
2+
3+
namespace Supabase;
44

55
class Exceptions extends Exception {
66
public static function Error()

src/Functions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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

77
class Functions extends Supabase
88
{

src/Supabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
declare(strict_types=1);
33

4-
namespace Supabase\Client;
4+
namespace Supabase;
55
use Exception;
66

77
class Supabase

src/Util/EnvSetup.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}

tests/SupabaseTest.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,21 @@
55
use PHPUnit\Framework\Attributes\CoversClass;
66
use PHPUnit\Framework\Attributes\Test;
77
use 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)]
1212
class 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
}

0 commit comments

Comments
 (0)