1
0
Fork 0
mirror of synced 2024-09-28 23:41:23 +12:00

Merge pull request #3631 from appwrite/fix-unit-tests

tests: fix unit tests
This commit is contained in:
Eldad A. Fux 2022-08-13 12:34:14 +03:00 committed by GitHub
commit cec8e9188b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 451 additions and 365 deletions

View file

@ -23,6 +23,7 @@
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"Tests\\E2E\\": "tests/e2e", "Tests\\E2E\\": "tests/e2e",
"Tests\\Unit\\": "tests/unit",
"Appwrite\\Tests\\": "tests/extensions" "Appwrite\\Tests\\": "tests/extensions"
} }
}, },

View file

@ -13,7 +13,7 @@
</extensions> </extensions>
<testsuites> <testsuites>
<testsuite name="unit"> <testsuite name="unit">
<directory>./tests/unit/</directory> <directory>./tests/unit</directory>
</testsuite> </testsuite>
<testsuite name="e2e"> <testsuite name="e2e">
<file>./tests/e2e/Client.php</file> <file>./tests/e2e/Client.php</file>

View file

@ -199,7 +199,7 @@ class Response extends SwooleResponse
/** /**
* @var array * @var array
*/ */
protected $payload = []; protected array $payload = [];
/** /**
* Response constructor. * Response constructor.
@ -300,8 +300,7 @@ class Response extends SwooleResponse
// Verification // Verification
// Recovery // Recovery
// Tests (keep last) // Tests (keep last)
->setModel(new Mock()) ->setModel(new Mock());
;
parent::__construct($response); parent::__construct($response);
} }
@ -391,12 +390,13 @@ class Response extends SwooleResponse
if ($model->isAny()) { if ($model->isAny()) {
$this->payload = $document->getArrayCopy(); $this->payload = $document->getArrayCopy();
return $this->payload; return $this->payload;
} }
foreach ($model->getRules() as $key => $rule) { foreach ($model->getRules() as $key => $rule) {
if (!$document->isSet($key) && $rule['require']) { // do not set attribute in response if not required if (!$document->isSet($key) && $rule['required']) { // do not set attribute in response if not required
if (!is_null($rule['default'])) { if (\array_key_exists('default', $rule)) {
$document->setAttribute($key, $rule['default']); $document->setAttribute($key, $rule['default']);
} else { } else {
throw new Exception('Model ' . $model->getName() . ' is missing response key: ' . $key); throw new Exception('Model ' . $model->getName() . ' is missing response key: ' . $key);
@ -408,7 +408,7 @@ class Response extends SwooleResponse
throw new Exception($key . ' must be an array of type ' . $rule['type']); throw new Exception($key . ' must be an array of type ' . $rule['type']);
} }
foreach ($data[$key] as &$item) { foreach ($data[$key] as $index => $item) {
if ($item instanceof Document) { if ($item instanceof Document) {
if (\is_array($rule['type'])) { if (\is_array($rule['type'])) {
foreach ($rule['type'] as $type) { foreach ($rule['type'] as $type) {
@ -432,9 +432,13 @@ class Response extends SwooleResponse
throw new Exception('Missing model for rule: ' . $ruleType); throw new Exception('Missing model for rule: ' . $ruleType);
} }
$item = $this->output($item, $ruleType); $data[$key][$index] = $this->output($item, $ruleType);
} }
} }
} else {
if ($data[$key] instanceof Document) {
$data[$key] = $this->output($data[$key], $rule['type']);
}
} }
$output[$key] = $data[$key]; $output[$key] = $data[$key];
@ -465,8 +469,7 @@ class Response extends SwooleResponse
$this $this
->setContentType(Response::CONTENT_TYPE_YAML) ->setContentType(Response::CONTENT_TYPE_YAML)
->send(yaml_emit($data, YAML_UTF8_ENCODING)) ->send(yaml_emit($data, YAML_UTF8_ENCODING));
;
} }
/** /**

View file

@ -15,22 +15,28 @@ abstract class Model
/** /**
* @var bool * @var bool
*/ */
protected $none = false; protected bool $none = false;
/** /**
* @var bool * @var bool
*/ */
protected $any = false; protected bool $any = false;
/** /**
* @var bool * @var bool
*/ */
protected $public = true; protected bool $public = true;
/** /**
* @var array * @var array
*/ */
protected $rules = []; protected array $rules = [];
/**
* @var array
*/
public array $conditions = [];
/** /**
* Filter Document Structure * Filter Document Structure
@ -76,12 +82,10 @@ abstract class Model
protected function addRule(string $key, array $options): self protected function addRule(string $key, array $options): self
{ {
$this->rules[$key] = array_merge([ $this->rules[$key] = array_merge([
'require' => true, 'required' => true,
'type' => '', 'array' => false,
'description' => '', 'description' => '',
'default' => null, 'example' => ''
'example' => '',
'array' => false
], $options); ], $options);
return $this; return $this;
@ -92,7 +96,7 @@ abstract class Model
$list = []; $list = [];
foreach ($this->rules as $key => $rule) { foreach ($this->rules as $key => $rule) {
if ($rule['require'] ?? false) { if ($rule['required'] ?? false) {
$list[] = $key; $list[] = $key;
} }
} }

View file

@ -10,7 +10,7 @@ class Any extends Model
/** /**
* @var bool * @var bool
*/ */
protected $any = true; protected bool $any = true;
/** /**
* Get Name * Get Name

View file

@ -39,7 +39,6 @@ class Attribute extends Model
'description' => 'Is attribute an array?', 'description' => 'Is attribute an array?',
'default' => false, 'default' => false,
'example' => false, 'example' => false,
'require' => false
]) ])
; ;
} }

View file

@ -28,9 +28,7 @@ class AttributeBoolean extends Attribute
'type' => self::TYPE_BOOLEAN, 'type' => self::TYPE_BOOLEAN,
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
'default' => null, 'default' => null,
'example' => false, 'example' => false
'array' => false,
'require' => false,
]) ])
; ;
} }

View file

@ -37,8 +37,6 @@ class AttributeEmail extends Attribute
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
'default' => null, 'default' => null,
'example' => 'default@example.com', 'example' => 'default@example.com',
'array' => false,
'require' => false,
]) ])
; ;
} }

View file

@ -30,7 +30,6 @@ class AttributeEnum extends Attribute
'default' => null, 'default' => null,
'example' => 'element', 'example' => 'element',
'array' => true, 'array' => true,
'require' => true,
]) ])
->addRule('format', [ ->addRule('format', [
'type' => self::TYPE_STRING, 'type' => self::TYPE_STRING,
@ -45,8 +44,6 @@ class AttributeEnum extends Attribute
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
'default' => null, 'default' => null,
'example' => 'element', 'example' => 'element',
'array' => false,
'require' => false,
]) ])
; ;
} }

View file

@ -29,24 +29,18 @@ class AttributeFloat extends Attribute
'description' => 'Minimum value to enforce for new documents.', 'description' => 'Minimum value to enforce for new documents.',
'default' => null, 'default' => null,
'example' => 1.5, 'example' => 1.5,
'array' => false,
'require' => false,
]) ])
->addRule('max', [ ->addRule('max', [
'type' => self::TYPE_FLOAT, 'type' => self::TYPE_FLOAT,
'description' => 'Maximum value to enforce for new documents.', 'description' => 'Maximum value to enforce for new documents.',
'default' => null, 'default' => null,
'example' => 10.5, 'example' => 10.5,
'array' => false,
'require' => false,
]) ])
->addRule('default', [ ->addRule('default', [
'type' => self::TYPE_FLOAT, 'type' => self::TYPE_FLOAT,
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
'default' => null, 'default' => null,
'example' => 2.5, 'example' => 2.5,
'array' => false,
'require' => false,
]) ])
; ;
} }

View file

@ -37,8 +37,6 @@ class AttributeIP extends Attribute
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
'default' => null, 'default' => null,
'example' => '192.0.2.0', 'example' => '192.0.2.0',
'array' => false,
'require' => false,
]) ])
; ;
} }

View file

@ -29,24 +29,18 @@ class AttributeInteger extends Attribute
'description' => 'Minimum value to enforce for new documents.', 'description' => 'Minimum value to enforce for new documents.',
'default' => null, 'default' => null,
'example' => 1, 'example' => 1,
'array' => false,
'require' => false,
]) ])
->addRule('max', [ ->addRule('max', [
'type' => self::TYPE_INTEGER, 'type' => self::TYPE_INTEGER,
'description' => 'Maximum value to enforce for new documents.', 'description' => 'Maximum value to enforce for new documents.',
'default' => null, 'default' => null,
'example' => 10, 'example' => 10,
'array' => false,
'require' => false,
]) ])
->addRule('default', [ ->addRule('default', [
'type' => self::TYPE_INTEGER, 'type' => self::TYPE_INTEGER,
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
'default' => null, 'default' => null,
'example' => 10, 'example' => 10,
'array' => false,
'require' => false,
]) ])
; ;
} }

View file

@ -23,8 +23,6 @@ class AttributeString extends Attribute
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
'default' => null, 'default' => null,
'example' => 'default', 'example' => 'default',
'array' => false,
'require' => false,
]) ])
; ;
} }

View file

@ -37,8 +37,6 @@ class AttributeURL extends Attribute
'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.', 'description' => 'Default value for attribute when not provided. Cannot be set when attribute is required.',
'default' => null, 'default' => null,
'example' => 'http://example.com', 'example' => 'http://example.com',
'array' => false,
'require' => false,
]) ])
; ;
} }

View file

@ -2,7 +2,6 @@
namespace Appwrite\Utopia\Response\Model; namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response\Model;
class BaseList extends Model class BaseList extends Model
@ -10,12 +9,12 @@ class BaseList extends Model
/** /**
* @var string * @var string
*/ */
protected $name = ''; protected string $name = '';
/** /**
* @var string * @var string
*/ */
protected $type = ''; protected string $type = '';
/** /**
* @param string $name * @param string $name

View file

@ -10,7 +10,7 @@ class Domain extends Model
/** /**
* @var bool * @var bool
*/ */
protected $public = false; protected bool $public = false;
public function __construct() public function __construct()
{ {

View file

@ -9,7 +9,7 @@ class ErrorDev extends Error
/** /**
* @var bool * @var bool
*/ */
protected $public = false; protected bool $public = false;
public function __construct() public function __construct()
{ {

View file

@ -41,7 +41,6 @@ class Index extends Model
'default' => [], 'default' => [],
'example' => [], 'example' => [],
'array' => true, 'array' => true,
'required' => false,
]) ])
; ;
} }

View file

@ -10,7 +10,7 @@ class Key extends Model
/** /**
* @var bool * @var bool
*/ */
protected $public = false; protected bool $public = false;
public function __construct() public function __construct()
{ {

View file

@ -16,7 +16,7 @@ class Metric extends Model
'default' => -1, 'default' => -1,
'example' => 1, 'example' => 1,
]) ])
->addRule('timestamp', [ ->addRule('date', [
'type' => self::TYPE_INTEGER, 'type' => self::TYPE_INTEGER,
'description' => 'The UNIX timestamp at which this metric was aggregated.', 'description' => 'The UNIX timestamp at which this metric was aggregated.',
'default' => 0, 'default' => 0,

View file

@ -10,7 +10,7 @@ class None extends Model
/** /**
* @var bool * @var bool
*/ */
protected $none = true; protected bool $none = true;
/** /**
* Get Name * Get Name

View file

@ -10,7 +10,7 @@ class Platform extends Model
/** /**
* @var bool * @var bool
*/ */
protected $public = false; protected bool $public = false;
public function __construct() public function __construct()
{ {

View file

@ -6,11 +6,6 @@ use Appwrite\Utopia\Response;
class Preferences extends Any class Preferences extends Any
{ {
/**
* @var bool
*/
protected $any = true;
/** /**
* Get Name * Get Name
* *

View file

@ -12,7 +12,7 @@ class Project extends Model
/** /**
* @var bool * @var bool
*/ */
protected $public = false; protected bool $public = false;
public function __construct() public function __construct()
{ {

View file

@ -10,7 +10,7 @@ class Webhook extends Model
/** /**
* @var bool * @var bool
*/ */
protected $public = false; protected bool $public = false;
public function __construct() public function __construct()
{ {

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Auth;
use Appwrite\Auth\Auth; use Appwrite\Auth\Auth;
use Utopia\Database\Document; use Utopia\Database\Document;
@ -9,10 +9,6 @@ use PHPUnit\Framework\TestCase;
class AuthTest extends TestCase class AuthTest extends TestCase
{ {
public function setUp(): void
{
}
/** /**
* Reset Roles * Reset Roles
*/ */
@ -22,7 +18,7 @@ class AuthTest extends TestCase
Authorization::setRole('role:all'); Authorization::setRole('role:all');
} }
public function testCookieName() public function testCookieName(): void
{ {
$name = 'cookie-name'; $name = 'cookie-name';
@ -30,7 +26,7 @@ class AuthTest extends TestCase
$this->assertEquals(Auth::$cookieName, $name); $this->assertEquals(Auth::$cookieName, $name);
} }
public function testEncodeDecodeSession() public function testEncodeDecodeSession(): void
{ {
$id = 'id'; $id = 'id';
$secret = 'secret'; $secret = 'secret';
@ -40,13 +36,13 @@ class AuthTest extends TestCase
$this->assertEquals(Auth::decodeSession($session), ['id' => $id, 'secret' => $secret]); $this->assertEquals(Auth::decodeSession($session), ['id' => $id, 'secret' => $secret]);
} }
public function testHash() public function testHash(): void
{ {
$secret = 'secret'; $secret = 'secret';
$this->assertEquals(Auth::hash($secret), '2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b'); $this->assertEquals(Auth::hash($secret), '2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b');
} }
public function testPassword() public function testPassword(): void
{ {
$secret = 'secret'; $secret = 'secret';
$static = '$2y$08$PDbMtV18J1KOBI9tIYabBuyUwBrtXPGhLxCy9pWP6xkldVOKLrLKy'; $static = '$2y$08$PDbMtV18J1KOBI9tIYabBuyUwBrtXPGhLxCy9pWP6xkldVOKLrLKy';
@ -56,19 +52,19 @@ class AuthTest extends TestCase
$this->assertEquals(Auth::passwordVerify($secret, $static), true); $this->assertEquals(Auth::passwordVerify($secret, $static), true);
} }
public function testPasswordGenerator() public function testPasswordGenerator(): void
{ {
$this->assertEquals(\mb_strlen(Auth::passwordGenerator()), 40); $this->assertEquals(\mb_strlen(Auth::passwordGenerator()), 40);
$this->assertEquals(\mb_strlen(Auth::passwordGenerator(5)), 10); $this->assertEquals(\mb_strlen(Auth::passwordGenerator(5)), 10);
} }
public function testTokenGenerator() public function testTokenGenerator(): void
{ {
$this->assertEquals(\mb_strlen(Auth::tokenGenerator()), 256); $this->assertEquals(\mb_strlen(Auth::tokenGenerator()), 256);
$this->assertEquals(\mb_strlen(Auth::tokenGenerator(5)), 10); $this->assertEquals(\mb_strlen(Auth::tokenGenerator(5)), 10);
} }
public function testSessionVerify() public function testSessionVerify(): void
{ {
$secret = 'secret1'; $secret = 'secret1';
$hash = Auth::hash($secret); $hash = Auth::hash($secret);
@ -112,7 +108,7 @@ class AuthTest extends TestCase
$this->assertEquals(Auth::sessionVerify($tokens2, 'false-secret'), false); $this->assertEquals(Auth::sessionVerify($tokens2, 'false-secret'), false);
} }
public function testTokenVerify() public function testTokenVerify(): void
{ {
$secret = 'secret1'; $secret = 'secret1';
$hash = Auth::hash($secret); $hash = Auth::hash($secret);
@ -169,7 +165,7 @@ class AuthTest extends TestCase
$this->assertEquals(Auth::tokenVerify($tokens3, Auth::TOKEN_TYPE_RECOVERY, 'false-secret'), false); $this->assertEquals(Auth::tokenVerify($tokens3, Auth::TOKEN_TYPE_RECOVERY, 'false-secret'), false);
} }
public function testIsPrivilegedUser() public function testIsPrivilegedUser(): void
{ {
$this->assertEquals(false, Auth::isPrivilegedUser([])); $this->assertEquals(false, Auth::isPrivilegedUser([]));
$this->assertEquals(false, Auth::isPrivilegedUser(['role:' . Auth::USER_ROLE_GUEST])); $this->assertEquals(false, Auth::isPrivilegedUser(['role:' . Auth::USER_ROLE_GUEST]));
@ -186,7 +182,7 @@ class AuthTest extends TestCase
$this->assertEquals(true, Auth::isPrivilegedUser(['role:' . Auth::USER_ROLE_OWNER, 'role:' . Auth::USER_ROLE_ADMIN, 'role:' . Auth::USER_ROLE_DEVELOPER])); $this->assertEquals(true, Auth::isPrivilegedUser(['role:' . Auth::USER_ROLE_OWNER, 'role:' . Auth::USER_ROLE_ADMIN, 'role:' . Auth::USER_ROLE_DEVELOPER]));
} }
public function testIsAppUser() public function testIsAppUser(): void
{ {
$this->assertEquals(false, Auth::isAppUser([])); $this->assertEquals(false, Auth::isAppUser([]));
$this->assertEquals(false, Auth::isAppUser(['role:' . Auth::USER_ROLE_GUEST])); $this->assertEquals(false, Auth::isAppUser(['role:' . Auth::USER_ROLE_GUEST]));
@ -203,7 +199,7 @@ class AuthTest extends TestCase
$this->assertEquals(false, Auth::isAppUser(['role:' . Auth::USER_ROLE_OWNER, 'role:' . Auth::USER_ROLE_ADMIN, 'role:' . Auth::USER_ROLE_DEVELOPER])); $this->assertEquals(false, Auth::isAppUser(['role:' . Auth::USER_ROLE_OWNER, 'role:' . Auth::USER_ROLE_ADMIN, 'role:' . Auth::USER_ROLE_DEVELOPER]));
} }
public function testGuestRoles() public function testGuestRoles(): void
{ {
$user = new Document([ $user = new Document([
'$id' => '' '$id' => ''
@ -214,7 +210,7 @@ class AuthTest extends TestCase
$this->assertContains('role:guest', $roles); $this->assertContains('role:guest', $roles);
} }
public function testUserRoles() public function testUserRoles(): void
{ {
$user = new Document([ $user = new Document([
'$id' => '123', '$id' => '123',
@ -247,7 +243,7 @@ class AuthTest extends TestCase
$this->assertContains('team:def/guest', $roles); $this->assertContains('team:def/guest', $roles);
} }
public function testPrivilegedUserRoles() public function testPrivilegedUserRoles(): void
{ {
Authorization::setRole('role:' . Auth::USER_ROLE_OWNER); Authorization::setRole('role:' . Auth::USER_ROLE_OWNER);
$user = new Document([ $user = new Document([
@ -281,7 +277,7 @@ class AuthTest extends TestCase
$this->assertContains('team:def/guest', $roles); $this->assertContains('team:def/guest', $roles);
} }
public function testAppUserRoles() public function testAppUserRoles(): void
{ {
Authorization::setRole('role:' . Auth::USER_ROLE_APP); Authorization::setRole('role:' . Auth::USER_ROLE_APP);
$user = new Document([ $user = new Document([

View file

@ -1,27 +1,20 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Auth\Validator;
use Appwrite\Auth\Validator\Password; use Appwrite\Auth\Validator\Password;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class PasswordTest extends TestCase class PasswordTest extends TestCase
{ {
/** protected ?Password $object = null;
* @var Password
*/
protected $object = null;
public function setUp(): void public function setUp(): void
{ {
$this->object = new Password(); $this->object = new Password();
} }
public function tearDown(): void public function testValues(): void
{
}
public function testValues()
{ {
$this->assertEquals($this->object->isValid(false), false); $this->assertEquals($this->object->isValid(false), false);
$this->assertEquals($this->object->isValid(null), false); $this->assertEquals($this->object->isValid(null), false);

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Auth\Validator;
use Appwrite\Auth\Validator\Phone; use Appwrite\Auth\Validator\Phone;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -14,11 +14,7 @@ class PhoneTest extends TestCase
$this->object = new Phone(); $this->object = new Phone();
} }
public function tearDown(): void public function testValues(): void
{
}
public function testValues()
{ {
$this->assertEquals($this->object->isValid(false), false); $this->assertEquals($this->object->isValid(false), false);
$this->assertEquals($this->object->isValid(null), false); $this->assertEquals($this->object->isValid(null), false);

View file

@ -1,20 +1,12 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\DSN;
use Appwrite\DSN\DSN; use Appwrite\DSN\DSN;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class DSNTest extends TestCase class DSNTest extends TestCase
{ {
public function setUp(): void
{
}
public function tearDown(): void
{
}
public function testSuccess(): void public function testSuccess(): void
{ {
$dsn = new DSN("mariadb://user:password@localhost:3306/database?charset=utf8&timezone=UTC"); $dsn = new DSN("mariadb://user:password@localhost:3306/database?charset=utf8&timezone=UTC");
@ -84,6 +76,6 @@ class DSNTest extends TestCase
public function testFail(): void public function testFail(): void
{ {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
$dsn = new DSN("mariadb://"); new DSN("mariadb://");
} }
} }

View file

@ -1,16 +1,13 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Detector;
use Appwrite\Detector\Detector; use Appwrite\Detector\Detector;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class DetectorTest extends TestCase class DetectorTest extends TestCase
{ {
/** protected ?Detector $object = null;
* @var Detector
*/
protected $object = null;
public function setUp(): void public function setUp(): void
{ {
@ -21,7 +18,7 @@ class DetectorTest extends TestCase
{ {
} }
public function testGetOS() public function testGetOS(): void
{ {
$this->assertEquals($this->object->getOS(), [ $this->assertEquals($this->object->getOS(), [
'osCode' => 'WIN', 'osCode' => 'WIN',
@ -30,7 +27,7 @@ class DetectorTest extends TestCase
]); ]);
} }
public function testGetClient() public function testGetClient(): void
{ {
$this->assertEquals($this->object->getClient(), [ $this->assertEquals($this->object->getClient(), [
'clientType' => 'browser', 'clientType' => 'browser',
@ -42,7 +39,7 @@ class DetectorTest extends TestCase
]); ]);
} }
public function testGetDevice() public function testGetDevice(): void
{ {
$this->assertEquals($this->object->getDevice(), [ $this->assertEquals($this->object->getDevice(), [
'deviceName' => 'desktop', 'deviceName' => 'desktop',

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Docker;
use Appwrite\Docker\Compose; use Appwrite\Docker\Compose;
use Exception; use Exception;
@ -8,11 +8,7 @@ use PHPUnit\Framework\TestCase;
class ComposeTest extends TestCase class ComposeTest extends TestCase
{ {
/** protected ?Compose $object = null;
* @var Compose
*/
protected $object = null;
public function setUp(): void public function setUp(): void
{ {
@ -25,16 +21,12 @@ class ComposeTest extends TestCase
$this->object = new Compose($data); $this->object = new Compose($data);
} }
public function tearDown(): void public function testVersion(): void
{
}
public function testVersion()
{ {
$this->assertEquals('3', $this->object->getVersion()); $this->assertEquals('3', $this->object->getVersion());
} }
public function testServices() public function testServices(): void
{ {
$this->assertCount(17, $this->object->getServices()); $this->assertCount(17, $this->object->getServices());
$this->assertEquals('appwrite-telegraf', $this->object->getService('telegraf')->getContainerName()); $this->assertEquals('appwrite-telegraf', $this->object->getService('telegraf')->getContainerName());
@ -44,12 +36,12 @@ class ComposeTest extends TestCase
$this->assertEquals(['2080' => '80', '2443' => '443', '8080' => '8080'], $this->object->getService('traefik')->getPorts()); $this->assertEquals(['2080' => '80', '2443' => '443', '8080' => '8080'], $this->object->getService('traefik')->getPorts());
} }
public function testNetworks() public function testNetworks(): void
{ {
$this->assertCount(2, $this->object->getNetworks()); $this->assertCount(2, $this->object->getNetworks());
} }
public function testVolumes() public function testVolumes(): void
{ {
$this->assertCount(9, $this->object->getVolumes()); $this->assertCount(9, $this->object->getVolumes());
$this->assertEquals('appwrite-mariadb', $this->object->getVolumes()[0]); $this->assertEquals('appwrite-mariadb', $this->object->getVolumes()[0]);

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Docker;
use Appwrite\Docker\Env; use Appwrite\Docker\Env;
use Exception; use Exception;
@ -8,11 +8,7 @@ use PHPUnit\Framework\TestCase;
class EnvTest extends TestCase class EnvTest extends TestCase
{ {
/** protected ?Env $object = null;
* @var Env
*/
protected $object = null;
public function setUp(): void public function setUp(): void
{ {
@ -25,11 +21,7 @@ class EnvTest extends TestCase
$this->object = new Env($data); $this->object = new Env($data);
} }
public function tearDown(): void public function testVars(): void
{
}
public function testVars()
{ {
$this->object->setVar('_APP_TEST', 'value4'); $this->object->setVar('_APP_TEST', 'value4');
@ -39,7 +31,7 @@ class EnvTest extends TestCase
$this->assertEquals('value4', $this->object->getVar('_APP_TEST')); $this->assertEquals('value4', $this->object->getVar('_APP_TEST'));
} }
public function testExport() public function testExport(): void
{ {
$this->assertEquals("_APP_X=value1 $this->assertEquals("_APP_X=value1
_APP_Y=value2 _APP_Y=value2

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Event;
use Appwrite\Event\Event; use Appwrite\Event\Event;
use InvalidArgumentException; use InvalidArgumentException;
@ -9,15 +9,8 @@ use Utopia\App;
class EventTest extends TestCase class EventTest extends TestCase
{ {
/** protected ?Event $object = null;
* @var Event protected string $queue = '';
*/
protected $object = null;
/**
* @var string
*/
protected $queue = '';
public function setUp(): void public function setUp(): void
{ {
@ -29,11 +22,7 @@ class EventTest extends TestCase
$this->object = new Event($this->queue, 'TestsV1'); $this->object = new Event($this->queue, 'TestsV1');
} }
public function tearDown(): void public function testQueue(): void
{
}
public function testQueue()
{ {
$this->assertEquals($this->queue, $this->object->getQueue()); $this->assertEquals($this->queue, $this->object->getQueue());
@ -44,7 +33,7 @@ class EventTest extends TestCase
$this->object->setQueue($this->queue); $this->object->setQueue($this->queue);
} }
public function testClass() public function testClass(): void
{ {
$this->assertEquals('TestsV1', $this->object->getClass()); $this->assertEquals('TestsV1', $this->object->getClass());
@ -55,7 +44,7 @@ class EventTest extends TestCase
$this->object->setClass('TestsV1'); $this->object->setClass('TestsV1');
} }
public function testParams() public function testParams(): void
{ {
$this->object $this->object
->setParam('eventKey1', 'eventValue1') ->setParam('eventKey1', 'eventValue1')
@ -69,7 +58,7 @@ class EventTest extends TestCase
$this->assertEquals(\Resque::size($this->queue), 1); $this->assertEquals(\Resque::size($this->queue), 1);
} }
public function testReset() public function testReset(): void
{ {
$this->object $this->object
->setParam('eventKey1', 'eventValue1') ->setParam('eventKey1', 'eventValue1')
@ -85,7 +74,7 @@ class EventTest extends TestCase
$this->assertEquals(null, $this->object->getParam('eventKey3')); $this->assertEquals(null, $this->object->getParam('eventKey3'));
} }
public function testGenerateEvents() public function testGenerateEvents(): void
{ {
$event = Event::generateEvents('users.[userId].create', [ $event = Event::generateEvents('users.[userId].create', [
'userId' => 'torsten' 'userId' => 'torsten'

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Event\Validator;
use Appwrite\Event\Validator\Event; use Appwrite\Event\Validator\Event;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -20,7 +20,7 @@ class EventValidatorTest extends TestCase
{ {
} }
public function testValues() public function testValues(): void
{ {
/** /**
* Test for SUCCESS * Test for SUCCESS

View file

@ -1,23 +1,19 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\General;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class CollectionsTest extends TestCase class CollectionsTest extends TestCase
{ {
protected $collections; protected array $collections;
public function setUp(): void public function setUp(): void
{ {
$this->collections = require('app/config/collections.php'); $this->collections = require('app/config/collections.php');
} }
public function tearDown(): void public function testDuplicateRules(): void
{
}
public function testDuplicateRules()
{ {
foreach ($this->collections as $key => $collection) { foreach ($this->collections as $key => $collection) {
if (array_key_exists('attributes', $collection)) { if (array_key_exists('attributes', $collection)) {

View file

@ -1,116 +1,77 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\General;
use Appwrite\Network\Validator\CNAME;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ExtensionsTest extends TestCase class ExtensionsTest extends TestCase
{ {
public function setUp(): void public function testPHPRedis(): void
{
// Core
// ctype
// curl
// date
// fileinfo
// filter
// ftp
// hash
// iconv
// libxml
// mysqlnd
// pcre
// pdo_mysql
// pdo_sqlite
// Phar
// posix
// readline
// Reflection
// session
// SimpleXML
// sockets
// sodium
// SPL
// sqlite3
// standard
// tokenizer
// xml
// xmlreader
// xmlwriter
// zlib
}
public function tearDown(): void
{
}
public function testPHPRedis()
{ {
$this->assertEquals(true, extension_loaded('redis')); $this->assertEquals(true, extension_loaded('redis'));
} }
public function testSwoole() public function testSwoole(): void
{ {
$this->assertEquals(true, extension_loaded('swoole')); $this->assertEquals(true, extension_loaded('swoole'));
} }
public function testYAML() public function testYAML(): void
{ {
$this->assertEquals(true, extension_loaded('yaml')); $this->assertEquals(true, extension_loaded('yaml'));
} }
public function testOPCache() public function testOPCache(): void
{ {
$this->assertEquals(true, extension_loaded('Zend OPcache')); $this->assertEquals(true, extension_loaded('Zend OPcache'));
} }
public function testDOM() public function testDOM(): void
{ {
$this->assertEquals(true, extension_loaded('dom')); $this->assertEquals(true, extension_loaded('dom'));
} }
public function testPDO() public function testPDO(): void
{ {
$this->assertEquals(true, extension_loaded('PDO')); $this->assertEquals(true, extension_loaded('PDO'));
} }
public function testImagick() public function testImagick(): void
{ {
$this->assertEquals(true, extension_loaded('imagick')); $this->assertEquals(true, extension_loaded('imagick'));
} }
public function testJSON() public function testJSON(): void
{ {
$this->assertEquals(true, extension_loaded('json')); $this->assertEquals(true, extension_loaded('json'));
} }
public function testCURL() public function testCURL(): void
{ {
$this->assertEquals(true, extension_loaded('curl')); $this->assertEquals(true, extension_loaded('curl'));
} }
public function testMBString() public function testMBString(): void
{ {
$this->assertEquals(true, extension_loaded('mbstring')); $this->assertEquals(true, extension_loaded('mbstring'));
} }
public function testOPENSSL() public function testOPENSSL(): void
{ {
$this->assertEquals(true, extension_loaded('openssl')); $this->assertEquals(true, extension_loaded('openssl'));
} }
public function testZLIB() public function testZLIB(): void
{ {
$this->assertEquals(true, extension_loaded('zlib')); $this->assertEquals(true, extension_loaded('zlib'));
} }
public function testSockets() public function testSockets(): void
{ {
$this->assertEquals(true, extension_loaded('sockets')); $this->assertEquals(true, extension_loaded('sockets'));
} }
public function testMaxminddb() public function testMaxminddb(): void
{ {
$this->assertEquals(true, extension_loaded('maxminddb')); $this->assertEquals(true, extension_loaded('maxminddb'));
} }

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Messaging;
use Appwrite\Auth\Auth; use Appwrite\Auth\Auth;
use Utopia\Database\Document; use Utopia\Database\Document;
@ -106,7 +106,7 @@ class MessagingChannelsTest extends TestCase
$this->connectionsCount = 0; $this->connectionsCount = 0;
} }
public function testSubscriptions() public function testSubscriptions(): void
{ {
/** /**
* Check for 1 project. * Check for 1 project.
@ -148,7 +148,7 @@ class MessagingChannelsTest extends TestCase
/** /**
* Tests Wildcard (role:all) Permissions on every channel. * Tests Wildcard (role:all) Permissions on every channel.
*/ */
public function testWildcardPermission() public function testWildcardPermission(): void
{ {
foreach ($this->allChannels as $index => $channel) { foreach ($this->allChannels as $index => $channel) {
$event = [ $event = [
@ -177,7 +177,7 @@ class MessagingChannelsTest extends TestCase
} }
} }
public function testRolePermissions() public function testRolePermissions(): void
{ {
$roles = ['role:guest', 'role:member']; $roles = ['role:guest', 'role:member'];
foreach ($this->allChannels as $index => $channel) { foreach ($this->allChannels as $index => $channel) {
@ -211,7 +211,7 @@ class MessagingChannelsTest extends TestCase
} }
} }
public function testUserPermissions() public function testUserPermissions(): void
{ {
foreach ($this->allChannels as $index => $channel) { foreach ($this->allChannels as $index => $channel) {
$permissions = []; $permissions = [];
@ -244,7 +244,7 @@ class MessagingChannelsTest extends TestCase
} }
} }
public function testTeamPermissions() public function testTeamPermissions(): void
{ {
foreach ($this->allChannels as $index => $channel) { foreach ($this->allChannels as $index => $channel) {
$permissions = []; $permissions = [];

View file

@ -1,13 +1,13 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Messaging;
use Appwrite\Messaging\Adapter\Realtime; use Appwrite\Messaging\Adapter\Realtime;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class MessagingGuestTest extends TestCase class MessagingGuestTest extends TestCase
{ {
public function testGuest() public function testGuest(): void
{ {
$realtime = new Realtime(); $realtime = new Realtime();

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Messaging;
use Utopia\Database\Document; use Utopia\Database\Document;
use Appwrite\Messaging\Adapter\Realtime; use Appwrite\Messaging\Adapter\Realtime;
@ -16,7 +16,7 @@ class MessagingTest extends TestCase
{ {
} }
public function testUser() public function testUser(): void
{ {
$realtime = new Realtime(); $realtime = new Realtime();
@ -134,7 +134,7 @@ class MessagingTest extends TestCase
$this->assertEmpty($realtime->subscriptions); $this->assertEmpty($realtime->subscriptions);
} }
public function testConvertChannelsGuest() public function testConvertChannelsGuest(): void
{ {
$user = new Document([ $user = new Document([
'$id' => '' '$id' => ''
@ -157,7 +157,7 @@ class MessagingTest extends TestCase
$this->assertArrayNotHasKey('account.456', $channels); $this->assertArrayNotHasKey('account.456', $channels);
} }
public function testConvertChannelsUser() public function testConvertChannelsUser(): void
{ {
$user = new Document([ $user = new Document([
'$id' => '123', '$id' => '123',

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Migration;
use Appwrite\Migration\Migration; use Appwrite\Migration\Migration;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -34,7 +34,7 @@ abstract class MigrationTest extends TestCase
/** /**
* Check versions array integrity. * Check versions array integrity.
*/ */
public function testMigrationVersions() public function testMigrationVersions(): void
{ {
require_once __DIR__ . '/../../../app/init.php'; require_once __DIR__ . '/../../../app/init.php';
@ -45,7 +45,7 @@ abstract class MigrationTest extends TestCase
$this->assertArrayHasKey(APP_VERSION_STABLE, Migration::$versions); $this->assertArrayHasKey(APP_VERSION_STABLE, Migration::$versions);
} }
public function testHasDifference() public function testHasDifference(): void
{ {
$this->assertFalse(Migration::hasDifference([], [])); $this->assertFalse(Migration::hasDifference([], []));
$this->assertFalse(Migration::hasDifference([ $this->assertFalse(Migration::hasDifference([

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Migration;
use ReflectionClass; use ReflectionClass;
use Appwrite\Migration\Version\V12; use Appwrite\Migration\Version\V12;
@ -16,7 +16,7 @@ class MigrationV12Test extends MigrationTest
$this->method->setAccessible(true); $this->method->setAccessible(true);
} }
public function testMigrationProjects() public function testMigrationProjects(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'project', '$id' => 'project',
@ -30,7 +30,7 @@ class MigrationV12Test extends MigrationTest
$this->assertEquals($document->getAttribute('search'), 'project Appwrite'); $this->assertEquals($document->getAttribute('search'), 'project Appwrite');
} }
public function testMigrationUsers() public function testMigrationUsers(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'user', '$id' => 'user',
@ -42,7 +42,7 @@ class MigrationV12Test extends MigrationTest
$this->assertEquals($document->getAttribute('search'), 'user test@appwrite.io Torsten Dittmann'); $this->assertEquals($document->getAttribute('search'), 'user test@appwrite.io Torsten Dittmann');
} }
public function testMigrationTeams() public function testMigrationTeams(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'team', '$id' => 'team',
@ -53,7 +53,7 @@ class MigrationV12Test extends MigrationTest
$this->assertEquals($document->getAttribute('search'), 'team Appwrite'); $this->assertEquals($document->getAttribute('search'), 'team Appwrite');
} }
public function testMigrationFunctions() public function testMigrationFunctions(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'function', '$id' => 'function',
@ -65,7 +65,7 @@ class MigrationV12Test extends MigrationTest
$this->assertEquals($document->getAttribute('search'), 'function My Function php-8.0'); $this->assertEquals($document->getAttribute('search'), 'function My Function php-8.0');
} }
public function testMigrationExecutions() public function testMigrationExecutions(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'execution', '$id' => 'execution',

View file

@ -1,8 +1,7 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Migration;
use Appwrite\Event\Validator\Event;
use ReflectionClass; use ReflectionClass;
use Appwrite\Migration\Version\V13; use Appwrite\Migration\Version\V13;
use Utopia\Database\Document; use Utopia\Database\Document;
@ -17,7 +16,7 @@ class MigrationV13Test extends MigrationTest
$this->method->setAccessible(true); $this->method->setAccessible(true);
} }
public function testMigrateFunctions() public function testMigrateFunctions(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'func', '$id' => 'func',
@ -28,7 +27,7 @@ class MigrationV13Test extends MigrationTest
$this->assertEquals($document->getAttribute('events'), ['users.*.create']); $this->assertEquals($document->getAttribute('events'), ['users.*.create']);
} }
public function testMigrationWebhooks() public function testMigrationWebhooks(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'webh', '$id' => 'webh',

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Migration;
use ReflectionClass; use ReflectionClass;
use Appwrite\Migration\Version\V14; use Appwrite\Migration\Version\V14;
@ -16,7 +16,7 @@ class MigrationV14Test extends MigrationTest
$this->method->setAccessible(true); $this->method->setAccessible(true);
} }
public function testMigrateProjects() public function testMigrateProjects(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'appwrite', '$id' => 'appwrite',
@ -28,7 +28,7 @@ class MigrationV14Test extends MigrationTest
$this->assertEquals($document->getAttribute('version'), '0.15.0'); $this->assertEquals($document->getAttribute('version'), '0.15.0');
} }
public function testMigrateKeys() public function testMigrateKeys(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'appwrite', '$id' => 'appwrite',
@ -39,7 +39,7 @@ class MigrationV14Test extends MigrationTest
$this->assertEquals($document->getAttribute('expire'), 0); $this->assertEquals($document->getAttribute('expire'), 0);
} }
public function testMigrateWebhooks() public function testMigrateWebhooks(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'appwrite', '$id' => 'appwrite',
@ -50,7 +50,7 @@ class MigrationV14Test extends MigrationTest
$this->assertEquals(strlen($document->getAttribute('signatureKey')), 128); $this->assertEquals(strlen($document->getAttribute('signatureKey')), 128);
} }
public function testMigrateUsers() public function testMigrateUsers(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'appwrite', '$id' => 'appwrite',
@ -62,7 +62,7 @@ class MigrationV14Test extends MigrationTest
$this->assertFalse($document->getAttribute('phoneVerification')); $this->assertFalse($document->getAttribute('phoneVerification'));
} }
public function testMigratePlatforms() public function testMigratePlatforms(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'appwrite', '$id' => 'appwrite',
@ -77,7 +77,7 @@ class MigrationV14Test extends MigrationTest
$this->assertEquals($document->getUpdatedAt(), 987654321); $this->assertEquals($document->getUpdatedAt(), 987654321);
} }
public function testMigrateFunctions() public function testMigrateFunctions(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'appwrite', '$id' => 'appwrite',
@ -92,7 +92,7 @@ class MigrationV14Test extends MigrationTest
$this->assertEquals($document->getUpdatedAt(), 987654321); $this->assertEquals($document->getUpdatedAt(), 987654321);
} }
public function testMigrateDeployments() public function testMigrateDeployments(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'appwrite', '$id' => 'appwrite',
@ -104,7 +104,7 @@ class MigrationV14Test extends MigrationTest
$this->assertEquals($document->getCreatedAt(), 123456789); $this->assertEquals($document->getCreatedAt(), 123456789);
} }
public function testMigrateExecutions() public function testMigrateExecutions(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'appwrite', '$id' => 'appwrite',
@ -116,7 +116,7 @@ class MigrationV14Test extends MigrationTest
$this->assertEquals($document->getCreatedAt(), 123456789); $this->assertEquals($document->getCreatedAt(), 123456789);
} }
public function testMigrateTeams() public function testMigrateTeams(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'appwrite', '$id' => 'appwrite',
@ -128,7 +128,7 @@ class MigrationV14Test extends MigrationTest
$this->assertEquals($document->getCreatedAt(), 123456789); $this->assertEquals($document->getCreatedAt(), 123456789);
} }
public function testMigrateAudits() public function testMigrateAudits(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'appwrite', '$id' => 'appwrite',
@ -151,7 +151,7 @@ class MigrationV14Test extends MigrationTest
$this->assertEquals($document->getAttribute('event'), 'databases.default.collections.movies.documents.avatar.create'); $this->assertEquals($document->getAttribute('event'), 'databases.default.collections.movies.documents.avatar.create');
} }
public function testMigrateStats() public function testMigrateStats(): void
{ {
$document = $this->fixDocument(new Document([ $document = $this->fixDocument(new Document([
'$id' => 'appwrite', '$id' => 'appwrite',

View file

@ -1,16 +1,13 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Network\Validators;
use Appwrite\Network\Validator\CNAME; use Appwrite\Network\Validator\CNAME;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class CNAMETest extends TestCase class CNAMETest extends TestCase
{ {
/** protected ?CNAME $object = null;
* @var CNAME
*/
protected $object = null;
public function setUp(): void public function setUp(): void
{ {
@ -21,7 +18,7 @@ class CNAMETest extends TestCase
{ {
} }
public function testValues() public function testValues(): void
{ {
$this->assertEquals($this->object->isValid(''), false); $this->assertEquals($this->object->isValid(''), false);
$this->assertEquals($this->object->isValid(null), false); $this->assertEquals($this->object->isValid(null), false);

View file

@ -1,16 +1,13 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Network\Validators;
use Appwrite\Network\Validator\Domain; use Appwrite\Network\Validator\Domain;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class DomainTest extends TestCase class DomainTest extends TestCase
{ {
/** protected ?Domain $domain = null;
* @var Domain
*/
protected $domain = null;
public function setUp(): void public function setUp(): void
{ {
@ -22,7 +19,7 @@ class DomainTest extends TestCase
$this->domain = null; $this->domain = null;
} }
public function testIsValid() public function testIsValid(): void
{ {
// Assertions // Assertions
$this->assertEquals(true, $this->domain->isValid('example.com')); $this->assertEquals(true, $this->domain->isValid('example.com'));

View file

@ -12,16 +12,14 @@
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php> * @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
*/ */
namespace Appwrite\Network\Validator; namespace Tests\Unit\Network\Validators;
use Appwrite\Network\Validator\Email;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class EmailTest extends TestCase class EmailTest extends TestCase
{ {
/** protected ?Email $email = null;
* @var Email
*/
protected $email = null;
public function setUp(): void public function setUp(): void
{ {
@ -33,9 +31,8 @@ class EmailTest extends TestCase
$this->email = null; $this->email = null;
} }
public function testIsValid() public function testIsValid(): void
{ {
// Assertions
$this->assertEquals(true, $this->email->isValid('email@domain.com')); $this->assertEquals(true, $this->email->isValid('email@domain.com'));
$this->assertEquals(true, $this->email->isValid('firstname.lastname@domain.com')); $this->assertEquals(true, $this->email->isValid('firstname.lastname@domain.com'));
$this->assertEquals(true, $this->email->isValid('email@subdomain.domain.com')); $this->assertEquals(true, $this->email->isValid('email@subdomain.domain.com'));

View file

@ -12,16 +12,14 @@
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php> * @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
*/ */
namespace Appwrite\Network\Validator; namespace Tests\Unit\Network\Validators;
use Appwrite\Network\Validator\Host;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class HostTest extends TestCase class HostTest extends TestCase
{ {
/** protected ?Host $host = null;
* @var Host
*/
protected $host = null;
public function setUp(): void public function setUp(): void
{ {
@ -33,7 +31,7 @@ class HostTest extends TestCase
$this->host = null; $this->host = null;
} }
public function testIsValid() public function testIsValid(): void
{ {
// Assertions // Assertions
$this->assertEquals($this->host->isValid('https://appwrite.io/link'), true); $this->assertEquals($this->host->isValid('https://appwrite.io/link'), true);

View file

@ -12,71 +12,76 @@
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php> * @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
*/ */
namespace Appwrite\Network\Validator; namespace Tests\Unit\Network\Validators;
use Appwrite\Network\Validator\IP;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class IPTest extends TestCase class IPTest extends TestCase
{ {
protected ?IP $validator;
public function setUp(): void
{
$this->validator = new IP();
}
public function tearDown(): void public function tearDown(): void
{ {
$this->validator = null; $this->validator = null;
} }
public function testIsValidIP() public function testIsValidIP(): void
{ {
$validator = new IP(); $this->assertEquals($this->validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true);
$this->assertEquals($this->validator->isValid('109.67.204.101'), true);
// Assertions $this->assertEquals($this->validator->isValid(23.5), false);
$this->assertEquals($validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true); $this->assertEquals($this->validator->isValid('23.5'), false);
$this->assertEquals($validator->isValid('109.67.204.101'), true); $this->assertEquals($this->validator->isValid(null), false);
$this->assertEquals($validator->isValid(23.5), false); $this->assertEquals($this->validator->isValid(true), false);
$this->assertEquals($validator->isValid('23.5'), false); $this->assertEquals($this->validator->isValid(false), false);
$this->assertEquals($validator->isValid(null), false); $this->assertEquals($this->validator->getType(), 'string');
$this->assertEquals($validator->isValid(true), false);
$this->assertEquals($validator->isValid(false), false);
$this->assertEquals($validator->getType(), 'string');
} }
public function testIsValidIPALL() public function testIsValidIPALL(): void
{ {
$validator = new IP(IP::ALL); $this->validator = new IP(IP::ALL);
// Assertions // Assertions
$this->assertEquals($validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true); $this->assertEquals($this->validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true);
$this->assertEquals($validator->isValid('109.67.204.101'), true); $this->assertEquals($this->validator->isValid('109.67.204.101'), true);
$this->assertEquals($validator->isValid(23.5), false); $this->assertEquals($this->validator->isValid(23.5), false);
$this->assertEquals($validator->isValid('23.5'), false); $this->assertEquals($this->validator->isValid('23.5'), false);
$this->assertEquals($validator->isValid(null), false); $this->assertEquals($this->validator->isValid(null), false);
$this->assertEquals($validator->isValid(true), false); $this->assertEquals($this->validator->isValid(true), false);
$this->assertEquals($validator->isValid(false), false); $this->assertEquals($this->validator->isValid(false), false);
} }
public function testIsValidIPV4() public function testIsValidIPV4(): void
{ {
$validator = new IP(IP::V4); $this->validator = new IP(IP::V4);
// Assertions // Assertions
$this->assertEquals($validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), false); $this->assertEquals($this->validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), false);
$this->assertEquals($validator->isValid('109.67.204.101'), true); $this->assertEquals($this->validator->isValid('109.67.204.101'), true);
$this->assertEquals($validator->isValid(23.5), false); $this->assertEquals($this->validator->isValid(23.5), false);
$this->assertEquals($validator->isValid('23.5'), false); $this->assertEquals($this->validator->isValid('23.5'), false);
$this->assertEquals($validator->isValid(null), false); $this->assertEquals($this->validator->isValid(null), false);
$this->assertEquals($validator->isValid(true), false); $this->assertEquals($this->validator->isValid(true), false);
$this->assertEquals($validator->isValid(false), false); $this->assertEquals($this->validator->isValid(false), false);
} }
public function testIsValidIPV6() public function testIsValidIPV6(): void
{ {
$validator = new IP(IP::V6); $this->validator = new IP(IP::V6);
// Assertions // Assertions
$this->assertEquals($validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true); $this->assertEquals($this->validator->isValid('2001:0db8:85a3:08d3:1319:8a2e:0370:7334'), true);
$this->assertEquals($validator->isValid('109.67.204.101'), false); $this->assertEquals($this->validator->isValid('109.67.204.101'), false);
$this->assertEquals($validator->isValid(23.5), false); $this->assertEquals($this->validator->isValid(23.5), false);
$this->assertEquals($validator->isValid('23.5'), false); $this->assertEquals($this->validator->isValid('23.5'), false);
$this->assertEquals($validator->isValid(null), false); $this->assertEquals($this->validator->isValid(null), false);
$this->assertEquals($validator->isValid(true), false); $this->assertEquals($this->validator->isValid(true), false);
$this->assertEquals($validator->isValid(false), false); $this->assertEquals($this->validator->isValid(false), false);
} }
} }

View file

@ -1,13 +1,13 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Network\Validators;
use Appwrite\Network\Validator\Origin; use Appwrite\Network\Validator\Origin;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class OriginTest extends TestCase class OriginTest extends TestCase
{ {
public function testValues() public function testValues(): void
{ {
$validator = new Origin([ $validator = new Origin([
[ [

View file

@ -12,8 +12,9 @@
* @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php> * @license The MIT License (MIT) <http://www.opensource.org/licenses/mit-license.php>
*/ */
namespace Appwrite\Network\Validator; namespace Tests\Unit\Network\Validators;
use Appwrite\Network\Validator\URL;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class URLTest extends TestCase class URLTest extends TestCase

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\OpenSSL;
use Appwrite\OpenSSL\OpenSSL; use Appwrite\OpenSSL\OpenSSL;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -15,7 +15,7 @@ class OpenSSLTest extends TestCase
{ {
} }
public function testEncryptionAndDecryption() public function testEncryptionAndDecryption(): void
{ {
$key = 'my-secret-key'; $key = 'my-secret-key';
$iv = ''; $iv = '';

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Stats;
use Appwrite\Stats\Stats; use Appwrite\Stats\Stats;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -28,13 +28,13 @@ class StatsTest extends TestCase
{ {
} }
public function testNamespace() public function testNamespace(): void
{ {
$this->object->setNamespace('appwritetest.usage'); $this->object->setNamespace('appwritetest.usage');
$this->assertEquals('appwritetest.usage', $this->object->getNamespace()); $this->assertEquals('appwritetest.usage', $this->object->getNamespace());
} }
public function testParams() public function testParams(): void
{ {
$this->object $this->object
->setParam('projectId', 'appwrite_test') ->setParam('projectId', 'appwrite_test')
@ -50,7 +50,7 @@ class StatsTest extends TestCase
$this->assertEquals(null, $this->object->getParam('networkRequestSize')); $this->assertEquals(null, $this->object->getParam('networkRequestSize'));
} }
public function testReset() public function testReset(): void
{ {
$this->object $this->object
->setParam('projectId', 'appwrite_test') ->setParam('projectId', 'appwrite_test')

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Validator;
use Appwrite\Task\Validator\Cron; use Appwrite\Task\Validator\Cron;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -21,7 +21,7 @@ class CronTest extends TestCase
{ {
} }
public function testValues() public function testValues(): void
{ {
$this->assertEquals($this->object->isValid('0 2 * * *'), true); // execute at 2am daily $this->assertEquals($this->object->isValid('0 2 * * *'), true); // execute at 2am daily
$this->assertEquals($this->object->isValid('0 5,17 * * *'), true); // execute twice a day $this->assertEquals($this->object->isValid('0 5,17 * * *'), true); // execute twice a day

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Template;
use Appwrite\Template\Template; use Appwrite\Template\Template;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -24,12 +24,12 @@ class TemplateTest extends TestCase
{ {
} }
public function testRender() public function testRender(): void
{ {
$this->assertEquals($this->object->render(), 'Hello WORLD'); $this->assertEquals($this->object->render(), 'Hello WORLD');
} }
public function testParseURL() public function testParseURL(): void
{ {
$url = $this->object->parseURL('https://appwrite.io/demo'); $url = $this->object->parseURL('https://appwrite.io/demo');
@ -38,7 +38,7 @@ class TemplateTest extends TestCase
$this->assertEquals($url['path'], '/demo'); $this->assertEquals($url['path'], '/demo');
} }
public function testUnParseURL() public function testUnParseURL(): void
{ {
$url = $this->object->parseURL('https://appwrite.io/demo'); $url = $this->object->parseURL('https://appwrite.io/demo');
@ -49,18 +49,18 @@ class TemplateTest extends TestCase
$this->assertEquals($this->object->unParseURL($url), 'http://example.com/new'); $this->assertEquals($this->object->unParseURL($url), 'http://example.com/new');
} }
public function testMergeQuery() public function testMergeQuery(): void
{ {
$this->assertEquals($this->object->mergeQuery('key1=value1&key2=value2', ['key1' => 'value3', 'key4' => 'value4']), 'key1=value3&key2=value2&key4=value4'); $this->assertEquals($this->object->mergeQuery('key1=value1&key2=value2', ['key1' => 'value3', 'key4' => 'value4']), 'key1=value3&key2=value2&key4=value4');
} }
public function testFromCamelCaseToSnake() public function testFromCamelCaseToSnake(): void
{ {
$this->assertEquals('app_write', Template::fromCamelCaseToSnake('appWrite')); $this->assertEquals('app_write', Template::fromCamelCaseToSnake('appWrite'));
$this->assertEquals('app_write', Template::fromCamelCaseToSnake('App Write')); $this->assertEquals('app_write', Template::fromCamelCaseToSnake('App Write'));
} }
public function testFromCamelCaseToDash() public function testFromCamelCaseToDash(): void
{ {
$this->assertEquals('app-write', Template::fromCamelCaseToDash('appWrite')); $this->assertEquals('app-write', Template::fromCamelCaseToDash('appWrite'));
$this->assertEquals('app-write', Template::fromCamelCaseToDash('App Write')); $this->assertEquals('app-write', Template::fromCamelCaseToDash('App Write'));

View file

@ -1,13 +1,13 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\URL;
use Appwrite\URL\URL; use Appwrite\URL\URL;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class URLTest extends TestCase class URLTest extends TestCase
{ {
public function testParse() public function testParse(): void
{ {
$url = URL::parse('https://appwrite.io:8080/path?query=string&param=value'); $url = URL::parse('https://appwrite.io:8080/path?query=string&param=value');
@ -28,7 +28,7 @@ class URLTest extends TestCase
$this->assertEquals('', $url['query']); $this->assertEquals('', $url['query']);
} }
public function testUnparse() public function testUnparse(): void
{ {
$url = URL::unparse([ $url = URL::unparse([
'scheme' => 'https', 'scheme' => 'https',
@ -88,7 +88,7 @@ class URLTest extends TestCase
$this->assertEquals('https://eldad:fux@appwrite.io/#bottom', $url); $this->assertEquals('https://eldad:fux@appwrite.io/#bottom', $url);
} }
public function testParseQuery() public function testParseQuery(): void
{ {
$result = URL::parseQuery('param1=value1&param2=value2'); $result = URL::parseQuery('param1=value1&param2=value2');
@ -96,7 +96,7 @@ class URLTest extends TestCase
$this->assertEquals(['param1' => 'value1', 'param2' => 'value2'], $result); $this->assertEquals(['param1' => 'value1', 'param2' => 'value2'], $result);
} }
public function testUnParseQuery() public function testUnParseQuery(): void
{ {
$result = URL::unparseQuery(['param1' => 'value1', 'param2' => 'value2']); $result = URL::unparseQuery(['param1' => 'value1', 'param2' => 'value2']);

View file

@ -1,6 +1,6 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Utopia\Database\Validator;
use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Database\Validator\CustomId;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -21,7 +21,7 @@ class CustomIdTest extends TestCase
{ {
} }
public function testValues() public function testValues(): void
{ {
$this->assertEquals($this->object->isValid('unique()'), true); $this->assertEquals($this->object->isValid('unique()'), true);
$this->assertEquals($this->object->isValid('unique)'), false); $this->assertEquals($this->object->isValid('unique)'), false);

View file

@ -0,0 +1,28 @@
<?php
namespace Tests\Unit\Utopia;
use Appwrite\Utopia\Response\Model;
class Lists extends Model
{
public function __construct()
{
$this
->addRule('singles', [
'type' => 'single',
'default' => '',
'array' => true
]);
}
public function getName(): string
{
return 'Lists';
}
public function getType(): string
{
return 'lists';
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace Tests\Unit\Utopia;
use Appwrite\Utopia\Response\Model;
class Nested extends Model
{
public function __construct()
{
$this
->addRule('lists', [
'type' => 'lists',
'default' => '',
])
->addRule('single', [
'type' => 'single',
'default' => ''
]);
}
public function getName(): string
{
return 'Nested';
}
public function getType(): string
{
return 'nested';
}
}

View file

@ -1,33 +1,144 @@
<?php <?php
namespace Appwrite\Tests; namespace Tests\Unit\Utopia;
use Exception;
use Appwrite\Utopia\Response; use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Filters\V11; use Appwrite\Utopia\Response\Filters\V11;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Swoole\Http\Response as SwooleResponse; use Swoole\Http\Response as SwooleResponse;
use Utopia\Database\Document;
class ResponseTest extends TestCase class ResponseTest extends TestCase
{ {
/** protected ?Response $response = null;
* @var Response
*/
protected $object = null;
public function setUp(): void public function setUp(): void
{ {
$this->object = new Response(new SwooleResponse()); $this->response = new Response(new SwooleResponse());
$this->response->setModel(new Single());
$this->response->setModel(new Lists());
$this->response->setModel(new Nested());
} }
public function testSetFilter() public function testSetFilter(): void
{ {
$this->assertEquals($this->object->hasFilter(), false); $this->assertEquals($this->response->hasFilter(), false);
$this->assertEquals($this->object->getFilter(), null); $this->assertEquals($this->response->getFilter(), null);
$filter = new V11(); $filter = new V11();
$this->object->setFilter($filter); $this->response->setFilter($filter);
$this->assertEquals($this->object->hasFilter(), true); $this->assertEquals($this->response->hasFilter(), true);
$this->assertEquals($this->object->getFilter(), $filter); $this->assertEquals($this->response->getFilter(), $filter);
}
public function testResponseModel(): void
{
$output = $this->response->output(new Document([
'string' => 'lorem ipsum',
'integer' => 123,
'boolean' => true,
'hidden' => 'secret',
]), 'single');
$this->assertArrayHasKey('string', $output);
$this->assertArrayHasKey('integer', $output);
$this->assertArrayHasKey('boolean', $output);
$this->assertArrayNotHasKey('hidden', $output);
}
public function testResponseModelRequired(): void
{
$output = $this->response->output(new Document([
'string' => 'lorem ipsum',
'integer' => 123,
'boolean' => true,
]), 'single');
$this->assertArrayHasKey('string', $output);
$this->assertArrayHasKey('integer', $output);
$this->assertArrayHasKey('boolean', $output);
$this->assertArrayHasKey('required', $output);
$this->assertEquals('default', $output['required']);
}
public function testResponseModelRequiredException(): void
{
$this->expectException(Exception::class);
$this->response->output(new Document([
'integer' => 123,
'boolean' => true,
]), 'single');
}
public function testResponseModelLists(): void
{
$output = $this->response->output(new Document([
'singles' => [
new Document([
'string' => 'lorem ipsum',
'integer' => 123,
'boolean' => true,
'hidden' => 'secret'
])
],
'hidden' => 'secret',
]), 'lists');
$this->assertArrayHasKey('singles', $output);
$this->assertArrayNotHasKey('hidden', $output);
$this->assertCount(1, $output['singles']);
$single = $output['singles'][0];
$this->assertArrayHasKey('string', $single);
$this->assertArrayHasKey('integer', $single);
$this->assertArrayHasKey('boolean', $single);
$this->assertArrayHasKey('required', $single);
$this->assertArrayNotHasKey('hidden', $single);
}
public function testResponseModelNested(): void
{
$output = $this->response->output(new Document([
'lists' => new Document([
'singles' => [
new Document([
'string' => 'lorem ipsum',
'integer' => 123,
'boolean' => true,
'hidden' => 'secret'
])
],
'hidden' => 'secret',
]),
'single' => new Document([
'string' => 'lorem ipsum',
'integer' => 123,
'boolean' => true,
'hidden' => 'secret'
]),
'hidden' => 'secret',
]), 'nested');
$this->assertArrayHasKey('lists', $output);
$this->assertArrayHasKey('single', $output);
$this->assertArrayNotHasKey('hidden', $output);
$this->assertCount(1, $output['lists']['singles']);
$single = $output['single'];
$this->assertArrayHasKey('string', $single);
$this->assertArrayHasKey('integer', $single);
$this->assertArrayHasKey('boolean', $single);
$this->assertArrayHasKey('required', $single);
$this->assertArrayNotHasKey('hidden', $single);
$singleFromArray = $output['lists']['singles'][0];
$this->assertArrayHasKey('string', $singleFromArray);
$this->assertArrayHasKey('integer', $singleFromArray);
$this->assertArrayHasKey('boolean', $singleFromArray);
$this->assertArrayHasKey('required', $single);
$this->assertArrayNotHasKey('hidden', $singleFromArray);
} }
} }

View file

@ -0,0 +1,43 @@
<?php
namespace Tests\Unit\Utopia;
use Appwrite\Utopia\Response\Model;
class Single extends Model
{
public function __construct()
{
$this
->addRule('string', [
'type' => self::TYPE_STRING,
'example' => '5e5ea5c16897e',
'required' => true
])
->addRule('integer', [
'type' => self::TYPE_INTEGER,
'default' => 0,
'example' => 1592981250,
])
->addRule('boolean', [
'type' => self::TYPE_BOOLEAN,
'default' => true,
'example' => true,
])
->addRule('required', [
'type' => self::TYPE_STRING,
'default' => 'default',
'required' => true
]);
}
public function getName(): string
{
return 'Single';
}
public function getType(): string
{
return 'single';
}
}