-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting the unit tests to run a little cleaner.
- Loading branch information
Showing
10 changed files
with
104 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Supabase\Util; | ||
|
||
use Dotenv\Dotenv; | ||
|
||
class EnvSetup | ||
{ | ||
public static function env($path): array | ||
{ | ||
// If the env vars are set and not empty use them | ||
$apiKey = getenv('API_KEY'); | ||
$refId = getenv('REFERENCE_ID'); | ||
|
||
// else check try to load the .env file in the $path | ||
if (empty($apiKey) || empty($refId)) { | ||
$loaded = Dotenv::createArrayBacked($path)->safeLoad(); | ||
if (key_exists('API_KEY', $loaded)) { | ||
$apiKey = $loaded['API_KEY']; | ||
} | ||
|
||
if (key_exists('REFERENCE_ID', $loaded)) { | ||
$refId = $loaded['REFERENCE_ID']; | ||
} | ||
} | ||
|
||
if (empty($apiKey)) { | ||
throw new \Exception('Could not load API_KEY'); | ||
} | ||
|
||
if (empty($refId)) { | ||
throw new \Exception('Could not load REFERENCE_ID'); | ||
} | ||
|
||
return [ | ||
'API_KEY' => $apiKey, | ||
'REFERENCE_ID' => $refId, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,162 +1,149 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
require 'vendor/autoload.php'; | ||
use PHPUnit\Framework\TestCase; | ||
use Spatie\Url\Url; | ||
|
||
use function PHPUnit\Framework\assertEquals; | ||
|
||
require __DIR__.'/../../src/PostgrestFilter.php'; | ||
|
||
final class PostgrestFilterTest extends TestCase | ||
{ | ||
private $filter; | ||
|
||
public function setup(): void | ||
{ | ||
parent::setUp(); | ||
\Dotenv\Dotenv::createImmutable(__DIR__); | ||
$dotenv = \Dotenv\Dotenv::createUnsafeImmutable(__DIR__, '/../../.env.test'); | ||
$dotenv->load(); | ||
$api_key = getenv('API_KEY'); | ||
$reference_id = getenv('REFERENCE_ID'); | ||
$url = Url::fromString('https://'.$reference_id.'.supabase.co'.'/rest/v1/'); | ||
$this->filter = new PostgrestFilter($url, $reference_id, $api_key); | ||
$url = Url::fromString('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/'); | ||
$this->filter = new PostgrestFilter($url); | ||
} | ||
//should look like this https://gpdefvsxamnscceccczu.supabase.co/rest/v1/countries?name=eq.Algeria&select=* | ||
|
||
public function testEq(): void | ||
{ | ||
$result = $this->filter->eq('name', 'Algeria'); | ||
print_r((string) $result->url); | ||
ob_flush(); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=eq.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=eq.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testNeq(): void | ||
{ | ||
$result = $this->filter->neq('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=neq.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=neq.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testGt(): void | ||
{ | ||
$result = $this->filter->gt('id', '1'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?id=gt.1', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?id=gt.1', (string) $result->url); | ||
} | ||
|
||
public function testGte(): void | ||
{ | ||
$result = $this->filter->gte('id', '1'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?id=gte.1', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?id=gte.1', (string) $result->url); | ||
} | ||
|
||
public function testLt(): void | ||
{ | ||
$result = $this->filter->lt('id', '1'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?id=lt.1', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?id=lt.1', (string) $result->url); | ||
} | ||
|
||
public function testLte(): void | ||
{ | ||
$result = $this->filter->lte('id', '1'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?id=lte.1', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?id=lte.1', (string) $result->url); | ||
} | ||
|
||
public function testLike(): void | ||
{ | ||
$result = $this->filter->like('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=like.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=like.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testiLike(): void | ||
{ | ||
$result = $this->filter->ilike('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=ilike.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=ilike.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testIs(): void | ||
{ | ||
$result = $this->filter->is('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=is.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=is.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testIn(): void | ||
{ | ||
$result = $this->filter->in('Algeria', ['countries', 'id']); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?Algeria=in.%28countries%2Cid%29', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?Algeria=in.%28countries%2Cid%29', (string) $result->url); | ||
} | ||
|
||
public function testContains(): void | ||
{ | ||
$result = $this->filter->contains('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=cs.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=cs.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testContainedBy(): void | ||
{ | ||
$result = $this->filter->containedBy('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=cd.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=cd.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testRangeGt(): void | ||
{ | ||
$result = $this->filter->rangeGt('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=sr.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=sr.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testRangeGte(): void | ||
{ | ||
$result = $this->filter->rangeGte('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=nxl.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=nxl.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testRangeLt(): void | ||
{ | ||
$result = $this->filter->rangeLt('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=sl.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=sl.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testRangeLte(): void | ||
{ | ||
$result = $this->filter->rangeLte('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=nxr.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=nxr.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testRangeAdjacent(): void | ||
{ | ||
$result = $this->filter->rangeAdjacent('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=adj.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=adj.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testOverlaps(): void | ||
{ | ||
$result = $this->filter->overlaps('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=ov.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=ov.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testMatch(): void | ||
{ | ||
$result = $this->filter->match('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?', (string) $result->url); | ||
} | ||
|
||
public function testNot(): void | ||
{ | ||
$result = $this->filter->not('name', 'IS', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=not.IS.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=not.IS.Algeria', (string) $result->url); | ||
} | ||
|
||
public function testOr(): void | ||
{ | ||
$result = $this->filter->or('name', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?0=or&1=%28name%29', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?0=or&1=%28name%29', (string) $result->url); | ||
} | ||
|
||
public function testFilter(): void | ||
{ | ||
$result = $this->filter->filter('name', 'IS', 'Algeria'); | ||
assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=IS.Algeria', (string) $result->url); | ||
$this->assertEquals('https://gpdefvsxamnscceccczu.supabase.co/rest/v1/?name=IS.Algeria', (string) $result->url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class PostgrestTransformTest extends TestCase | ||
{ | ||
private $query; | ||
public $url; | ||
|
||
public function setup(): void | ||
{ | ||
parent::setUp(); | ||
\Dotenv\Dotenv::createImmutable(__DIR__); | ||
$dotenv = \Dotenv\Dotenv::createUnsafeImmutable(__DIR__, '/../../.env.test'); | ||
$dotenv->load(); | ||
$api_key = getenv('API_KEY'); | ||
$reference_id = getenv('REFERENCE_ID'); | ||
$this->query = new \Supabase\Postgrest\PostgrestQuery($reference_id, $api_key, $opts = []); | ||
} | ||
|
||
|
||
} |