-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
688e2c2
commit cb11459
Showing
8 changed files
with
309 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
namespace Appwrite; | ||
use PHPUnit\Framework\TestCase; | ||
final class IDTest extends TestCase { | ||
public function testUnique(): void { | ||
$this->assertSame('unique()', ID::unique()); | ||
} | ||
public function testCustom(): void { | ||
$this->assertSame('custom', ID::custom('custom')); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
namespace Appwrite; | ||
use PHPUnit\Framework\TestCase; | ||
final class PermissionTest extends TestCase { | ||
public function testRead(): void { | ||
$this->assertSame('read("any")', Permission::read(Role::any())); | ||
} | ||
public function testWrite(): void { | ||
$this->assertSame('write("any")', Permission::write(Role::any())); | ||
} | ||
public function testCreate(): void { | ||
$this->assertSame('create("any")', Permission::create(Role::any())); | ||
} | ||
public function testUpdate(): void { | ||
$this->assertSame('update("any")', Permission::update(Role::any())); | ||
} | ||
public function testDelete(): void { | ||
$this->assertSame('delete("any")', Permission::delete(Role::any())); | ||
} | ||
} |
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,149 @@ | ||
<?php | ||
namespace Appwrite; | ||
use PHPUnit\Framework\TestCase; | ||
final class BasicFilterQueryTest { | ||
public string $description; | ||
public mixed $value; | ||
public string $expectedValues; | ||
public function __construct(string $description, mixed $value, string $expectedValues) { | ||
$this->description = $description; | ||
$this->value = $value; | ||
$this->expectedValues = $expectedValues; | ||
} | ||
} | ||
final class QueryTest extends TestCase { | ||
/** | ||
* @var BasicFilterQueryTest[] $tests | ||
*/ | ||
private array $tests; | ||
function __construct(string $name) | ||
{ | ||
parent::__construct($name); | ||
$this->tests = array( | ||
new BasicFilterQueryTest('with a string', 's', '["s"]'), | ||
new BasicFilterQueryTest('with a integer', 1, '[1]'), | ||
new BasicFilterQueryTest('with a double', 1.2, '[1.2]'), | ||
new BasicFilterQueryTest('with a whole number double', 1.0, '[1]'), | ||
new BasicFilterQueryTest('with a bool', false, '[false]'), | ||
new BasicFilterQueryTest('with a list', ['a', 'b', 'c'], '["a","b","c"]'), | ||
); | ||
} | ||
public function testBasicFilterEqual(): void { | ||
foreach($this->tests as $test) { | ||
$this->assertSame( | ||
"equal(\"attr\", $test->expectedValues)", | ||
Query::equal('attr', $test->value), | ||
$test->description, | ||
); | ||
} | ||
} | ||
public function testBasicFilterNotEqual(): void { | ||
foreach($this->tests as $test) { | ||
$this->assertSame( | ||
"notEqual(\"attr\", $test->expectedValues)", | ||
Query::notEqual('attr', $test->value), | ||
$test->description, | ||
); | ||
} | ||
} | ||
public function testBasicFilterLessThan(): void { | ||
foreach($this->tests as $test) { | ||
$this->assertSame( | ||
"lessThan(\"attr\", $test->expectedValues)", | ||
Query::lessThan('attr', $test->value), | ||
$test->description, | ||
); | ||
} | ||
} | ||
public function testBasicFilterLessThanEqual(): void { | ||
foreach($this->tests as $test) { | ||
$this->assertSame( | ||
"lessThanEqual(\"attr\", $test->expectedValues)", | ||
Query::lessThanEqual('attr', $test->value), | ||
$test->description, | ||
); | ||
} | ||
} | ||
public function testBasicFilterGreaterThan(): void { | ||
foreach($this->tests as $test) { | ||
$this->assertSame( | ||
"greaterThan(\"attr\", $test->expectedValues)", | ||
Query::greaterThan('attr', $test->value), | ||
$test->description, | ||
); | ||
} | ||
} | ||
public function testBasicFilterGreaterThanEqual(): void { | ||
foreach($this->tests as $test) { | ||
$this->assertSame( | ||
"greaterThanEqual(\"attr\", $test->expectedValues)", | ||
Query::greaterThanEqual('attr', $test->value), | ||
$test->description, | ||
); | ||
} | ||
} | ||
public function testSearch(): void { | ||
$this->assertSame('search("attr", ["keyword1 keyword2"])', Query::search('attr', 'keyword1 keyword2')); | ||
} | ||
public function testIsNull(): void { | ||
$this->assertSame('isNull("attr")', Query::isNull('attr')); | ||
} | ||
public function testIsNotNull(): void { | ||
$this->assertSame('isNotNull("attr")', Query::isNotNull('attr')); | ||
} | ||
public function testBetweenWithIntegers(): void { | ||
$this->assertSame('between("attr", [1,2])', Query::between('attr', 1, 2)); | ||
} | ||
public function testBetweenWithDoubles(): void { | ||
$this->assertSame('between("attr", [1,2])', Query::between('attr', 1.0, 2.0)); | ||
} | ||
public function testBetweenWithStrings(): void { | ||
$this->assertSame('between("attr", ["a","z"])', Query::between('attr', 'a', 'z')); | ||
} | ||
public function testSelect(): void { | ||
$this->assertSame('select(["attr1","attr2"])', Query::select(['attr1', 'attr2'])); | ||
} | ||
public function testOrderAsc(): void { | ||
$this->assertSame('orderAsc("attr")', Query::orderAsc('attr')); | ||
} | ||
public function testOrderDesc(): void { | ||
$this->assertSame('orderDesc("attr")', Query::orderDesc('attr')); | ||
} | ||
public function testCursorBefore(): void { | ||
$this->assertSame('cursorBefore("attr")', Query::cursorBefore('attr')); | ||
} | ||
public function testCursorAfter(): void { | ||
$this->assertSame('cursorAfter("attr")', Query::cursorAfter('attr')); | ||
} | ||
public function testLimit(): void { | ||
$this->assertSame('limit(1)', Query::limit(1)); | ||
} | ||
public function testOffset(): void { | ||
$this->assertSame('offset(1)', Query::offset(1)); | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
namespace Appwrite; | ||
use PHPUnit\Framework\TestCase; | ||
final class RoleTest extends TestCase { | ||
public function testAny(): void { | ||
$this->assertSame('any', Role::any()); | ||
} | ||
public function testUserWithoutStatus(): void { | ||
$this->assertSame('user:custom', Role::user('custom')); | ||
} | ||
public function testUserWithStatus(): void { | ||
$this->assertSame('user:custom/verified', Role::user('custom', 'verified')); | ||
} | ||
public function testUsersWithoutStatus(): void { | ||
$this->assertSame('users', Role::users()); | ||
} | ||
public function testUsersWithStatus(): void { | ||
$this->assertSame('users/verified', Role::users('verified')); | ||
} | ||
public function testGuests(): void { | ||
$this->assertSame('guests', Role::guests()); | ||
} | ||
public function testTeamWithoutRole(): void { | ||
$this->assertSame('team:custom', Role::team('custom')); | ||
} | ||
public function testTeamWithRole(): void { | ||
$this->assertSame('team:custom/owner', Role::team('custom', 'owner')); | ||
} | ||
public function testMember(): void { | ||
$this->assertSame('member:custom', Role::member('custom')); | ||
} | ||
public function testLabel(): void { | ||
$this->assertSame('label:admin', Role::label('admin')); | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
namespace Appwrite\Services; | ||
use Appwrite\Client; | ||
use Appwrite\InputFile; | ||
use Mockery; | ||
use PHPUnit\Framework\TestCase; | ||
final class {{service.name | caseUcfirst}}Test extends TestCase { | ||
private Client $client; | ||
private {{service.name | caseUcfirst}} ${{service.name | caseCamel}}; | ||
protected function setUp(): void { | ||
$this->client = Mockery::mock(Client::class); | ||
$this->{{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}($this->client); | ||
} | ||
{% for method in service.methods %} | ||
public function testMethod{{method.name | caseUcfirst}}(): void { | ||
{%~ if method.responseModel and method.responseModel != 'any' ~%} | ||
$data = array( | ||
{%- for definition in spec.definitions ~%}{%~ if definition.name == method.responseModel -%}{%~ for property in definition.properties | filter((param) => param.required) ~%} | ||
"{{property.name | escapeDollarSign}}" => {% if property.type == 'object' %}array(){% elseif property.type == 'array' %}array(){% elseif property.type == 'string' %}"{{property.example | escapeDollarSign}}"{% elseif property.type == 'boolean' %}true{% else %}{{property.example}}{% endif %},{%~ endfor ~%}{% set break = true %}{%- else -%}{% set continue = true %}{%- endif -%}{%~ endfor -%} | ||
); | ||
{%~ elseif (method.responseModel and method.responseModel == 'any') or method.type == 'webAuth' ~%} | ||
$data = array(); | ||
{%~ else ~%} | ||
$data = ''; | ||
{%~ endif ~%} | ||
$this->client | ||
->allows()->call(Mockery::any(), Mockery::any(), Mockery::any(), Mockery::any()) | ||
->andReturn($data); | ||
$response = $this->{{service.name | caseCamel}}->{{method.name | caseCamel}}({%~ for parameter in method.parameters.all | filter((param) => param.required) ~%} | ||
{{parameter.name | escapeKeyword | caseCamel}}: {% if parameter.type == 'object' %}array(){% elseif parameter.type == 'array' %}array(){% elseif parameter.type == 'file' %}InputFile::withData('', "image/png"){% elseif parameter.type == 'boolean' %}true{% elseif parameter.type == 'string' %}"{% if parameter.example is not empty %}{{parameter.example | escapeDollarSign}}{% endif %}"{% elseif parameter.type == 'integer' and parameter['x-example'] is empty %}1{% elseif parameter.type == 'number' and parameter['x-example'] is empty %}1.0{% else %}{{parameter.example}}{%~ endif ~%},{%~ endfor ~%} | ||
); | ||
$this->assertSame($data, $response); | ||
} | ||
{% endfor %} | ||
} |