Skip to content

Commit 4b8ef32

Browse files
add tests
1 parent d87da58 commit 4b8ef32

10 files changed

Lines changed: 215 additions & 201 deletions

File tree

.github/workflows/tests.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
tests:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v6
19+
20+
- name: Setup PHP with PECL extension
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: '8.4'
24+
25+
- name: Validate composer.json and composer.lock
26+
run: composer validate --strict
27+
28+
- name: Cache Composer packages
29+
id: composer-cache
30+
uses: actions/cache@v5
31+
with:
32+
path: vendor
33+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
34+
restore-keys: |
35+
${{ runner.os }}-php-
36+
37+
- name: Install dependencies
38+
run: composer install --prefer-dist --no-progress
39+
40+
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
41+
# Docs: https://getcomposer.org/doc/articles/scripts.md
42+
43+
- name: Run test suite
44+
run: composer run-script test:unit

composer.json

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@
99
"supabase-sdk"
1010
],
1111
"type": "library",
12+
"license": "MIT",
1213
"require": {
13-
"php": "^8.2.0",
14-
"vlucas/phpdotenv": "^5.6"
14+
"php": "^8.3",
15+
"ext-curl": "*",
16+
"ext-json": "*",
17+
"psr/http-client": "^1.0",
18+
"psr/http-factory": "^1.1",
19+
"psr/http-message": "^2.0"
1520
},
1621
"require-dev": {
17-
"pestphp/pest": "^3.8",
18-
"phpstan/phpstan": "^2.1"
22+
"laravel/pint": "^1.29",
23+
"phpstan/extension-installer": "^1.4",
24+
"phpunit/phpunit": "^13.1",
25+
"phpstan/phpstan": "^2.1",
26+
"tomasvotruba/type-coverage": "^2.1"
1927
},
20-
"license": "MIT",
2128
"autoload": {
2229
"psr-4": {
2330
"Supabase\\Client\\": "src/"
@@ -40,24 +47,36 @@
4047
},
4148
{
4249
"name": "Ashish Kumbhar",
43-
"email": "ashishkumbhar01@hotmail.com",
4450
"role": "Developer"
4551
}
4652
],
4753
"funding": [
4854
{
4955
"type": "Open Collective",
5056
"url": "https://opencollective.com/CodeWithSushil"
57+
},
58+
{
59+
"type": "github",
60+
"url": "https://github.com/CodeWithSushil"
5161
}
5262
],
53-
"minimum-stability": "dev",
54-
"prefer-stable": true,
5563
"config": {
5664
"optimize-autoloader": true,
5765
"sort-packages": true,
5866
"preferred-install": "dist",
5967
"allow-plugins": {
60-
"pestphp/pest-plugin": true
68+
"phpstan/extension-installer": true
6169
}
62-
}
70+
},
71+
"scripts": {
72+
"lint": "pint",
73+
"test:type": "phpstan analyse",
74+
"test:unit": "phpunit",
75+
"test": [
76+
"@test:type",
77+
"@test:unit"
78+
]
79+
},
80+
"minimum-stability": "dev",
81+
"prefer-stable": true
6382
}

phpunit.xml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
>
5+
cacheDirectory=".phpunit.cache"
6+
executionOrder="depends,defects"
7+
requireCoverageMetadata="true"
8+
beStrictAboutCoverageMetadata="true"
9+
beStrictAboutOutputDuringTests="true"
10+
displayDetailsOnPhpunitDeprecations="true"
11+
failOnPhpunitDeprecation="true"
12+
failOnRisky="true"
13+
failOnWarning="true" colors="true">
714
<testsuites>
8-
<testsuite name="Test Suite">
9-
<directory suffix="Test.php">./tests</directory>
15+
<testsuite name="default">
16+
<directory>tests</directory>
1017
</testsuite>
1118
</testsuites>
12-
<source>
19+
20+
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
1321
<include>
14-
<directory>app</directory>
1522
<directory>src</directory>
1623
</include>
1724
</source>

src/Exceptions.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php
2+
23
declare(strict_types=1);
4+
35
namespace Supabase\Client;
46

5-
class Exceptions extends Exception {
6-
public static function Error()
7-
{
8-
throw new Exception('Error');
9-
}
10-
};
7+
class Exceptions extends Exception
8+
{
9+
public static function Error()
10+
{
11+
throw new Exception('Error');
12+
}
13+
}

src/Functions.php

Lines changed: 99 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,112 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace Supabase\Client;
5-
use Supabase\Client\Supabase;
66

77
class Functions extends Supabase
88
{
9-
public function getAllData(?string $table=null)
10-
{
11-
if (!isset($table)) {
12-
echo "Please provide your Supabase table name.";
13-
} else {
14-
$path = "$this->url/$table";
15-
$html = $this->grab($path, "GET");
16-
$data = json_decode($html, true);
17-
return $data;
9+
public function getAllData(?string $table = null)
10+
{
11+
if (! isset($table)) {
12+
echo 'Please provide your Supabase table name.';
13+
} else {
14+
$path = "$this->url/$table";
15+
$html = $this->grab($path, 'GET');
16+
$data = json_decode($html, true);
17+
18+
return $data;
19+
}
20+
}
21+
22+
public function getSingleData(?string $table = null, array $query = [])
23+
{
24+
if (! isset($table)) {
25+
echo 'Please provide your Supabase table name.';
26+
} elseif (! isset($query)) {
27+
echo 'Please provide your column name.';
28+
} else {
29+
$path = "$this->url/$table?select=$query";
30+
$html = $this->grab($path, 'GET');
31+
$data = json_decode($html, true);
32+
33+
return $data;
34+
}
35+
}
36+
37+
public function postData(?string $table = null, array $query = [], ?string $on_conflict = null)
38+
{
39+
if (! isset($table)) {
40+
echo 'Please provide your Supabase table name.';
41+
} elseif (! isset($query)) {
42+
echo 'Please provide your data.';
43+
} else {
44+
// If $on_conflict is provided, append to the path
45+
if (! empty($on_conflict)) {
46+
$path = "$this->url/$table?on_conflict=$on_conflict";
47+
} else {
48+
$path = "$this->url/$table";
49+
}
50+
51+
$html = $this->grab($path, 'POST', json_encode($query));
52+
53+
return $html;
54+
}
55+
}
56+
57+
public function updateData(?string $table = null, ?int $id = null, array $query = [])
58+
{
59+
if (! isset($table)) {
60+
echo 'Please provide your Supabase table name.';
61+
} elseif (! isset($id)) {
62+
echo 'Please provide id.';
63+
} elseif (! isset($query)) {
64+
echo 'Please provide your data.';
65+
} else {
66+
$path = "$this->url/$table?id=eq.$id";
67+
$html = $this->grab($path, 'PATCH', json_encode($query));
68+
69+
return $html;
70+
}
1871
}
19-
}
20-
21-
public function getSingleData(?string $table=null, array $query=[])
22-
{
23-
if (!isset($table)) {
24-
echo "Please provide your Supabase table name.";
25-
} elseif(!isset($query)) {
26-
echo "Please provide your column name.";
27-
} else {
28-
$path = "$this->url/$table?select=$query";
29-
$html = $this->grab($path, "GET");
30-
$data = json_decode($html, true);
31-
return $data;
72+
73+
public function deleteData(?string $table = null, ?int $id = null)
74+
{
75+
if (! isset($table)) {
76+
echo 'Please provide your Supabase table name.';
77+
} elseif (! isset($id)) {
78+
echo 'Please provide id.';
79+
} else {
80+
$path = "$this->url/$table?id=eq.$id";
81+
$html = $this->grab($path, 'DELETE');
82+
83+
return $html;
84+
}
3285
}
33-
}
34-
35-
public function postData(?string $table=null, array $query=[], ?string $on_conflict=null)
36-
{
37-
if (!isset($table)) {
38-
echo "Please provide your Supabase table name.";
39-
} elseif (!isset($query)) {
40-
echo "Please provide your data.";
41-
} else {
42-
// If $on_conflict is provided, append to the path
43-
if (!empty($on_conflict)) {
44-
$path = "$this->url/$table?on_conflict=$on_conflict";
45-
} else {
46-
$path = "$this->url/$table";
47-
}
48-
49-
$html = $this->grab($path, "POST", json_encode($query));
50-
return $html;
51-
}
52-
}
53-
54-
public function updateData(?string $table=null, ?int $id=null, array $query=[])
55-
{
56-
if (!isset($table)) {
57-
echo "Please provide your Supabase table name.";
58-
} elseif (!isset($id)) {
59-
echo "Please provide id.";
60-
} elseif (!isset($query)) {
61-
echo "Please provide your data.";
62-
} else {
63-
$path = "$this->url/$table?id=eq.$id";
64-
$html = $this->grab($path, "PATCH", json_encode($query));
65-
return $html;
86+
87+
public function pages(?string $table = null)
88+
{
89+
$path = "$this->url/$table?select=*";
90+
$html = $this->grab($path, 'GET');
91+
$data = json_decode($html, true);
92+
93+
return $data;
6694
}
67-
}
68-
69-
public function deleteData(?string $table=null, ?int $id=null)
70-
{
71-
if (!isset($table)) {
72-
echo "Please provide your Supabase table name.";
73-
} elseif (!isset($id)) {
74-
echo "Please provide id.";
75-
} else {
76-
$path = "$this->url/$table?id=eq.$id";
77-
$html = $this->grab($path, "DELETE");
78-
return $html;
95+
96+
public function filter(?string $table = null, ?int $range = null)
97+
{
98+
$path = "$this->url/$table?id=eq.$range&select=*";
99+
$html = $this->grab($path, 'GET');
100+
$data = json_decode($html, true);
101+
102+
return $data;
79103
}
80-
}
81-
82-
public function pages(?string $table=null)
83-
{
84-
$path = "$this->url/$table?select=*";
85-
$html = $this->grab($path, "GET");
86-
$data = json_decode($html, true);
87-
return $data;
88-
}
89-
90-
public function filter(?string $table=null, ?int $range=null)
91-
{
92-
$path = "$this->url/$table?id=eq.$range&select=*";
93-
$html = $this->grab($path, "GET");
94-
$data = json_decode($html, true);
95-
return $data;
96-
}
97-
98-
public function matchs(?string $table=null, array $query=[])
99-
{
100-
$path = "$this->url/$table";
101-
$html = $this->grab($path, "POST", json_encode($query));
102-
return $html;
103-
}
104104

105+
public function matchs(?string $table = null, array $query = [])
106+
{
107+
$path = "$this->url/$table";
108+
$html = $this->grab($path, 'POST', json_encode($query));
109+
110+
return $html;
111+
}
105112
}

0 commit comments

Comments
 (0)