1
0
Fork 0
mirror of synced 2024-09-29 17:01:37 +13:00

Merge branch 'master' of github.com:appwrite/appwrite

This commit is contained in:
eldadfux 2019-11-07 07:10:04 +02:00
commit 30b5773e1f
11 changed files with 118 additions and 117 deletions

View file

@ -25,7 +25,7 @@
* OAuth path is now /auth/login/oauth instead of /auth/oauth and /auth/oauth/callback is now /auth/login/oauth/callback, this is for better consistency with new login methods we will introduce in the future
# Version 0.3.0
# Version 0.3.0 (PRE-RELEASE)
## Features

View file

@ -15,7 +15,7 @@ class BaseConsole extends TestCase
protected $demoEmail = '';
protected $demoPassword = '';
public function setUp()
protected function setUp(): void
{
$this->client = new Client();
@ -27,7 +27,7 @@ class BaseConsole extends TestCase
$this->demoPassword = 'password.' . rand(0, 1000000);
}
public function tearDown()
protected function tearDown(): void
{
$this->client = null;
}
@ -49,7 +49,7 @@ class BaseConsole extends TestCase
return $response;
}
public function initProject(array $scopes) {
public function initProject(array $scopes): array {
$response = $this->register();
$this->assertEquals('http://localhost/success', $response['headers']['location']);

View file

@ -12,7 +12,7 @@ class BaseProjects extends BaseConsole
protected $projectsDemoEmail = '';
protected $projectsDemoPassword = '';
public function setUp()
protected function setUp(): void
{
parent::setUp();
@ -20,7 +20,7 @@ class BaseProjects extends BaseConsole
$this->projectsDemoPassword = 'password.' . rand(0, 1000000);
}
public function tearDown()
protected function tearDown(): void
{
parent::tearDown();

View file

@ -54,9 +54,9 @@ class Client
*
* @param string $value
*
* @return Client
* @return self $this
*/
public function setProject($value)
public function setProject(string $value): self
{
$this->addHeader('X-Appwrite-Project', $value);
@ -70,9 +70,9 @@ class Client
*
* @param string $value
*
* @return Client
* @return self $this
*/
public function setKey($value)
public function setKey(string $value): self
{
$this->addHeader('X-Appwrite-Key', $value);
@ -84,9 +84,9 @@ class Client
*
* @param string $value
*
* @return Client
* @return self $this
*/
public function setLocale($value)
public function setLocale(string $value): self
{
$this->addHeader('X-Appwrite-Locale', $value);
@ -98,32 +98,31 @@ class Client
*
* @param string $value
*
* @return Client
* @return self $this
*/
public function setMode($value)
public function setMode(string $value): self
{
$this->addHeader('X-Appwrite-Mode', $value);
return $this;
}
/***
* @param bool $status
* @return $this
/**
* @param bool $status true
* @return self $this
*/
public function setSelfSigned($status = true)
public function setSelfSigned(bool $status = true): self
{
$this->selfSigned = $status;
return $this;
}
/***
* @param $endpoint
* @return $this
/**
* @param mixed $endpoint
* @return self $this
*/
public function setEndpoint($endpoint)
public function setEndpoint($endpoint): self
{
$this->endpoint = $endpoint;
@ -131,10 +130,12 @@ class Client
}
/**
* @param $key
* @param $value
* @param string $key
* @param string $value
*
* @return self $this
*/
public function addHeader($key, $value)
public function addHeader(string $key, string $value): self
{
$this->headers[strtolower($key)] = strtolower($value);
@ -153,7 +154,7 @@ class Client
* @return array|string
* @throws Exception
*/
public function call($method, $path = '', $headers = array(), array $params = array())
public function call(string $method, string $path = '', array $headers = [], array $params = [])
{
$headers = array_merge($this->headers, $headers);
$ch = curl_init($this->endpoint . $path . (($method == self::METHOD_GET && !empty($params)) ? '?' . http_build_query($params) : ''));
@ -238,7 +239,7 @@ class Client
* @param string $cookie
* @return array
*/
public function parseCookie($cookie)
public function parseCookie(string $cookie): array
{
$cookies = [];
@ -254,7 +255,7 @@ class Client
* @param string $prefix
* @return array
*/
protected function flatten(array $data, $prefix = '')
protected function flatten(array $data, string $prefix = ''): array
{
$output = [];

View file

@ -6,7 +6,7 @@ use Tests\E2E\Client;
class ConsoleHealthTest extends BaseConsole
{
public function testHTTPSuccess()
public function testHTTPSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health', [
'origin' => 'http://localhost',
@ -17,7 +17,7 @@ class ConsoleHealthTest extends BaseConsole
$this->assertEquals('OK', $response['body']['status']);
}
public function testDBSuccess()
public function testDBSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health/db', [
'origin' => 'http://localhost',
@ -28,7 +28,7 @@ class ConsoleHealthTest extends BaseConsole
$this->assertEquals('OK', $response['body']['status']);
}
public function testCacheSuccess()
public function testCacheSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health/db', [
'origin' => 'http://localhost',
@ -39,7 +39,7 @@ class ConsoleHealthTest extends BaseConsole
$this->assertEquals('OK', $response['body']['status']);
}
public function testTimeSuccess()
public function testTimeSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health/time', [
'origin' => 'http://localhost',
@ -54,7 +54,7 @@ class ConsoleHealthTest extends BaseConsole
$this->assertLessThan(10, $response['body']['diff']);
}
public function testWebhooksSuccess()
public function testWebhooksSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health/webhooks', [
'origin' => 'http://localhost',
@ -66,7 +66,7 @@ class ConsoleHealthTest extends BaseConsole
$this->assertLessThan(10, $response['body']['size']);
}
public function xtestStorageLocalSuccess()
public function xtestStorageLocalSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health/storage/local', [
'origin' => 'http://localhost',
@ -77,7 +77,7 @@ class ConsoleHealthTest extends BaseConsole
$this->assertEquals('OK', $response['body']['status']);
}
public function testStorageAntiVirusSuccess()
public function testStorageAntiVirusSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health/storage/anti-virus', [
'origin' => 'http://localhost',

View file

@ -6,7 +6,7 @@ use Tests\E2E\Client;
class ConsoleProjectsTest extends BaseConsole
{
public function testRegisterSuccess()
public function testRegisterSuccess(): array
{
$response = $this->register();
@ -25,7 +25,7 @@ class ConsoleProjectsTest extends BaseConsole
/**
* @depends testRegisterSuccess
*/
public function testProjectsList($data)
public function testProjectsList($data): void
{
$response = $this->client->call(Client::METHOD_GET, '/projects', [
'origin' => 'http://localhost',
@ -40,7 +40,7 @@ class ConsoleProjectsTest extends BaseConsole
/**
* @depends testRegisterSuccess
*/
public function testProjectsCreateSuccess($data)
public function testProjectsCreateSuccess(array $data): array
{
$team = $this->client->call(Client::METHOD_POST, '/teams', [
'origin' => 'http://localhost',
@ -83,7 +83,7 @@ class ConsoleProjectsTest extends BaseConsole
/**
* @depends testProjectsCreateSuccess
*/
public function testProjectsUpdateSuccess($data)
public function testProjectsUpdateSuccess(array $data): void
{
$response = $this->client->call(Client::METHOD_POST, '/projects', [
'origin' => 'http://localhost',

View file

@ -6,7 +6,7 @@ use Tests\E2E\Client;
class ConsoleTest extends BaseConsole
{
public function testRegisterSuccess()
public function testRegisterSuccess(): array
{
$response = $this->register();
@ -22,7 +22,7 @@ class ConsoleTest extends BaseConsole
/**
* @depends testRegisterSuccess
*/
public function testLoginSuccess($data)
public function testLoginSuccess(array $data): array
{
$response = $this->client->call(Client::METHOD_POST, '/auth/login', [
'origin' => 'http://localhost',
@ -49,7 +49,7 @@ class ConsoleTest extends BaseConsole
/**
* @depends testLoginSuccess
*/
public function testAccountSuccess($data)
public function testAccountSuccess(array $data): array
{
$response = $this->client->call(Client::METHOD_GET, '/account', [
'origin' => 'http://localhost',
@ -72,7 +72,7 @@ class ConsoleTest extends BaseConsole
/**
* @depends testAccountSuccess
*/
public function testLogoutSuccess($data)
public function testLogoutSuccess(array $data): void
{
$response = $this->client->call(Client::METHOD_DELETE, '/auth/logout', [
'origin' => 'http://localhost',
@ -84,7 +84,7 @@ class ConsoleTest extends BaseConsole
$this->assertEquals('success', $response['body']['result']);
}
public function testLogoutFailure()
public function testLogoutFailure(): void
{
$response = $this->client->call(Client::METHOD_DELETE, '/auth/logout', [
'origin' => 'http://localhost',

View file

@ -6,7 +6,7 @@ use Tests\E2E\Client;
class ProjectAvatarsTest extends BaseProjects
{
public function testRegisterSuccess()
public function testRegisterSuccess(): array
{
return $this->initProject([]);
}
@ -14,7 +14,7 @@ class ProjectAvatarsTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testAvatarsCCReadSuccess($data)
public function testAvatarsCCReadSuccess(array $data): array
{
$logo = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [
'x-appwrite-project' => $data['projectUid'],
@ -53,7 +53,7 @@ class ProjectAvatarsTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testAvatarsBrowserReadSuccess($data)
public function testAvatarsBrowserReadSuccess(array $data): array
{
$logo = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [
'x-appwrite-project' => $data['projectUid'],
@ -92,7 +92,7 @@ class ProjectAvatarsTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testAvatarsFlagReadSuccess($data)
public function testAvatarsFlagReadSuccess(array $data): array
{
$logo = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [
'x-appwrite-project' => $data['projectUid'],
@ -131,7 +131,7 @@ class ProjectAvatarsTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testAvatarsRemoteImageReadSuccess($data)
public function testAvatarsRemoteImageReadSuccess(array $data): array
{
$logo = $this->client->call(Client::METHOD_GET, '/avatars/image', [
'x-appwrite-project' => $data['projectUid'],
@ -174,7 +174,7 @@ class ProjectAvatarsTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testAvatarsFaviconReadSuccess($data)
public function testAvatarsFaviconReadSuccess(array $data): array
{
$logo = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [
'x-appwrite-project' => $data['projectUid'],
@ -192,7 +192,7 @@ class ProjectAvatarsTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testAvatarsQRReadSuccess($data)
public function testAvatarsQRReadSuccess(array $data): array
{
$logo = $this->client->call(Client::METHOD_GET, '/avatars/qr', [
'x-appwrite-project' => $data['projectUid'],

View file

@ -6,7 +6,7 @@ use Tests\E2E\Client;
class ProjectDatabaseTest extends BaseProjects
{
public function testRegisterSuccess()
public function testRegisterSuccess(): array
{
return $this->initProject(['collections.read', 'collections.write', 'documents.read', 'documents.write',]);
}
@ -14,7 +14,7 @@ class ProjectDatabaseTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testCollectionCreateSuccess($data)
public function testCollectionCreateSuccess(array $data): array
{
$actors = $this->client->call(Client::METHOD_POST, '/database', [
'content-type' => 'application/json',
@ -50,8 +50,8 @@ class ProjectDatabaseTest extends BaseProjects
$this->assertIsArray($actors['body']['$permissions']);
$this->assertIsArray($actors['body']['$permissions']['read']);
$this->assertIsArray($actors['body']['$permissions']['write']);
$this->assertEquals(count($actors['body']['$permissions']['read']), 1);
$this->assertEquals(count($actors['body']['$permissions']['write']), 2);
$this->assertCount(1, $actors['body']['$permissions']['read']);
$this->assertCount(2, $actors['body']['$permissions']['write']);
$movies = $this->client->call(Client::METHOD_POST, '/database', [
'content-type' => 'application/json',
@ -96,8 +96,8 @@ class ProjectDatabaseTest extends BaseProjects
$this->assertIsArray($movies['body']['$permissions']);
$this->assertIsArray($movies['body']['$permissions']['read']);
$this->assertIsArray($movies['body']['$permissions']['write']);
$this->assertEquals(count($movies['body']['$permissions']['read']), 1);
$this->assertEquals(count($movies['body']['$permissions']['write']), 2);
$this->assertCount(1, $movies['body']['$permissions']['read']);
$this->assertCount(2, $movies['body']['$permissions']['write']);
return array_merge($data, ['moviesId' => $movies['body']['$uid'], 'actorsId' => $actors['body']['$uid']]);
}
@ -105,7 +105,7 @@ class ProjectDatabaseTest extends BaseProjects
/**
* @depends testCollectionCreateSuccess
*/
public function testDocumentCreateSuccess($data)
public function testDocumentCreateSuccess(array $data): array
{
$document1 = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', [
'content-type' => 'application/json',
@ -205,9 +205,9 @@ class ProjectDatabaseTest extends BaseProjects
$this->assertIsArray($document1['body']['$permissions']);
$this->assertIsArray($document1['body']['$permissions']['read']);
$this->assertIsArray($document1['body']['$permissions']['write']);
$this->assertEquals(count($document1['body']['$permissions']['read']), 0);
$this->assertEquals(count($document1['body']['$permissions']['write']), 0);
$this->assertEquals(count($document1['body']['actors']), 2);
$this->assertCount(0, $document1['body']['$permissions']['read']);
$this->assertCount(0, $document1['body']['$permissions']['write']);
$this->assertCount(2, $document1['body']['actors']);
$this->assertEquals($document2['headers']['status-code'], 201);
$this->assertEquals($document2['body']['$collection'], $data['moviesId']);
@ -216,9 +216,9 @@ class ProjectDatabaseTest extends BaseProjects
$this->assertIsArray($document2['body']['$permissions']);
$this->assertIsArray($document2['body']['$permissions']['read']);
$this->assertIsArray($document2['body']['$permissions']['write']);
$this->assertEquals(count($document2['body']['$permissions']['read']), 0);
$this->assertEquals(count($document2['body']['$permissions']['write']), 0);
$this->assertEquals(count($document2['body']['actors']), 3);
$this->assertCount(0, $document2['body']['$permissions']['read']);
$this->assertCount(0, $document2['body']['$permissions']['write']);
$this->assertCount(3, $document2['body']['actors']);
$this->assertEquals($document2['body']['actors'][0]['firstName'], 'Tom');
$this->assertEquals($document2['body']['actors'][0]['lastName'], 'Holland');
$this->assertEquals($document2['body']['actors'][1]['firstName'], 'Zendaya');
@ -233,9 +233,9 @@ class ProjectDatabaseTest extends BaseProjects
$this->assertIsArray($document3['body']['$permissions']);
$this->assertIsArray($document3['body']['$permissions']['read']);
$this->assertIsArray($document3['body']['$permissions']['write']);
$this->assertEquals(count($document3['body']['$permissions']['read']), 0);
$this->assertEquals(count($document3['body']['$permissions']['write']), 0);
$this->assertEquals(count($document3['body']['actors']), 2);
$this->assertCount(0, $document3['body']['$permissions']['read']);
$this->assertCount(0, $document3['body']['$permissions']['write']);
$this->assertCount(2, $document3['body']['actors']);
$this->assertEquals($document3['body']['actors'][0]['firstName'], 'Tom');
$this->assertEquals($document3['body']['actors'][0]['lastName'], 'Holland');
$this->assertEquals($document3['body']['actors'][1]['firstName'], 'Zendaya');
@ -249,7 +249,7 @@ class ProjectDatabaseTest extends BaseProjects
/**
* @depends testDocumentCreateSuccess
*/
public function testDocumentsListSuccessOrderAndCasting($data)
public function testDocumentsListSuccessOrderAndCasting(array $data): void
{
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
'content-type' => 'application/json',
@ -285,7 +285,7 @@ class ProjectDatabaseTest extends BaseProjects
/**
* @depends testDocumentCreateSuccess
*/
public function testDocumentsListSuccessLimitAndOffset($data)
public function testDocumentsListSuccessLimitAndOffset(array $data): void
{
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
'content-type' => 'application/json',
@ -321,7 +321,7 @@ class ProjectDatabaseTest extends BaseProjects
/**
* @depends testDocumentCreateSuccess
*/
public function testDocumentsListSuccessFirstAndLast($data)
public function testDocumentsListSuccessFirstAndLast(array $data): void
{
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
'content-type' => 'application/json',
@ -356,7 +356,7 @@ class ProjectDatabaseTest extends BaseProjects
/**
* @depends testDocumentCreateSuccess
*/
public function testDocumentsListSuccessSerach($data)
public function testDocumentsListSuccessSearch(array $data): void
{
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
'content-type' => 'application/json',
@ -396,7 +396,7 @@ class ProjectDatabaseTest extends BaseProjects
/**
* @depends testDocumentCreateSuccess
*/
public function testDocumentsListSuccessFilters($data)
public function testDocumentsListSuccessFilters(array $data): void
{
$documents = $this->client->call(Client::METHOD_GET, '/database/' . $data['moviesId'] . '/documents', [
'content-type' => 'application/json',
@ -443,7 +443,7 @@ class ProjectDatabaseTest extends BaseProjects
/**
* @depends testDocumentCreateSuccess
*/
public function testDocumentsUpdateSuccess($data)
public function testDocumentsUpdateSuccess(array $data): void
{
$document = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', [
'content-type' => 'application/json',
@ -495,7 +495,7 @@ class ProjectDatabaseTest extends BaseProjects
/**
* @depends testDocumentCreateSuccess
*/
public function testDocumentsDeleteSuccess($data)
public function testDocumentsDeleteSuccess(array $data): void
{
$document = $this->client->call(Client::METHOD_POST, '/database/' . $data['moviesId'] . '/documents', [
'content-type' => 'application/json',

View file

@ -6,7 +6,7 @@ use Tests\E2E\Client;
class ProjectLocaleTest extends BaseProjects
{
public function testRegisterSuccess()
public function testRegisterSuccess(): array
{
return $this->initProject([]);
}
@ -14,7 +14,7 @@ class ProjectLocaleTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testLocaleReadSuccess($data)
public function testLocaleReadSuccess(array $data): array
{
$locale = $this->client->call(Client::METHOD_GET, '/locale', [
'content-type' => 'application/json',
@ -36,7 +36,7 @@ class ProjectLocaleTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testLocaleCountriesReadSuccess($data)
public function testLocaleCountriesReadSuccess(array $data): array
{
$countries = $this->client->call(Client::METHOD_GET, '/locale/countries', [
'content-type' => 'application/json',
@ -66,7 +66,7 @@ class ProjectLocaleTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testLocaleCountriesEUReadSuccess($data)
public function testLocaleCountriesEUReadSuccess(array $data): array
{
$countries = $this->client->call(Client::METHOD_GET, '/locale/countries/eu', [
'content-type' => 'application/json',
@ -96,7 +96,7 @@ class ProjectLocaleTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testLocaleContinentsReadSuccess($data)
public function testLocaleContinentsReadSuccess(array $data): array
{
$continents = $this->client->call(Client::METHOD_GET, '/locale/continents', [
'content-type' => 'application/json',
@ -125,7 +125,7 @@ class ProjectLocaleTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testLocaleCurrenciesReadSuccess($data)
public function testLocaleCurrenciesReadSuccess(array $data): array
{
$continents = $this->client->call(Client::METHOD_GET, '/locale/currencies', [
'content-type' => 'application/json',

View file

@ -6,7 +6,7 @@ use Tests\E2E\Client;
class ProjectUsersTest extends BaseProjects
{
public function testRegisterSuccess()
public function testRegisterSuccess(): array
{
return $this->initProject(['users.read', 'users.write']);
}
@ -14,7 +14,7 @@ class ProjectUsersTest extends BaseProjects
/**
* @depends testRegisterSuccess
*/
public function testUserCreateSuccess($data)
public function testUserCreateSuccess(array $data): array
{
$user = $this->client->call(Client::METHOD_POST, '/users', [
'content-type' => 'application/json',
@ -39,7 +39,7 @@ class ProjectUsersTest extends BaseProjects
/**
* @depends testUserCreateSuccess
*/
public function testUserReadSuccess($data)
public function testUserReadSuccess(array $data): array
{
$user = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'], [
'content-type' => 'application/json',
@ -106,7 +106,7 @@ class ProjectUsersTest extends BaseProjects
/**
* @depends testUserReadSuccess
*/
public function testUserUpdateStatusSuccess($data)
public function testUserUpdateStatusSuccess(array $data): array
{
$user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/status', [
'content-type' => 'application/json',
@ -134,7 +134,7 @@ class ProjectUsersTest extends BaseProjects
/**
* @depends testUserReadSuccess
*/
public function testUserUpdatePrefsSuccess($data)
public function testUserUpdatePrefsSuccess(array $data): array
{
$user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/prefs', [
'content-type' => 'application/json',