Skip to content

Commit 9b1397c

Browse files
Auth class add
1 parent 7ac4c3a commit 9b1397c

File tree

4 files changed

+47
-32
lines changed

4 files changed

+47
-32
lines changed

src/Auth/Auth.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
class Auth {
3+
//
4+
}

src/Client.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ class Client
1212

1313
public function __construct(string $url, string $key)
1414
{
15+
if (!filter_var($url, FILTER_VALIDATE_URL)) {
16+
throw new \InvalidArgumentException("Invalid URL: $url");
17+
} else if(!is_string($key)){
18+
throw \InvalidArgumentException("Invalid apiKey: $key");
19+
}else{
20+
1521
$this->url = $url;
1622
$this->apiKey = $key;
23+
}
1724
}
1825
}

tests/ClientTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests;
6+
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\Attributes\Test;
9+
use PHPUnit\Framework\TestCase;
10+
use Supabase\Client;
11+
12+
#[CoversClass(Client::class)]
13+
final class ClientTest extends TestCase
14+
{
15+
#[Test]
16+
public function it_can_be_instantiated(): void
17+
{
18+
$key = 'test-api-key';
19+
$url = 'https://api.example.com';
20+
21+
$client = new Client($key, $url);
22+
23+
$this->assertInstanceOf(Client::class, $client);
24+
}
25+
26+
#[Test]
27+
public function it_throws_exception_with_invalid_url(): void
28+
{
29+
$this->expectException(\InvalidArgumentException::class);
30+
31+
$key = 'test-api-key';
32+
$url = 'https://example.com';
33+
34+
new Client($key, $url);
35+
}
36+
}

tests/Setup.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)