From ae75313b2beeeda15fcc07f4ca71aa6fcbafc712 Mon Sep 17 00:00:00 2001 From: stanislav shupilkin Date: Fri, 26 May 2023 15:20:15 +0400 Subject: [PATCH] Fix all files with php-cs-fixer v3.17.0 --- examples/common-part.php | 15 +++-- examples/config.json | 4 +- src/Reindexer/BaseService.php | 15 +++-- src/Reindexer/Client/Api.php | 18 ++++-- src/Reindexer/Client/BaseApi.php | 12 ++-- src/Reindexer/Entities/Entity.php | 9 ++- src/Reindexer/Entities/Index.php | 63 ++++++++++++------- src/Reindexer/Entities/SdlQuery.php | 3 +- src/Reindexer/Enum/CollateMode.php | 3 +- src/Reindexer/Enum/FieldType.php | 3 +- src/Reindexer/Enum/IndexType.php | 3 +- src/Reindexer/LoggerInterface.php | 3 +- src/Reindexer/Response.php | 48 +++++++++----- src/Reindexer/Services/Database.php | 12 ++-- src/Reindexer/Services/Index.php | 12 ++-- src/Reindexer/Services/Item.php | 27 +++++--- src/Reindexer/Services/Namespaces.php | 33 ++++++---- src/Reindexer/Services/Query.php | 18 ++++-- tests/Feature/Reindexer/Fixture/HabrPost.php | 3 +- tests/Feature/Reindexer/ServiceTest.php | 24 ++++--- tests/Unit/Reindexer/BaseTest.php | 15 +++-- tests/Unit/Reindexer/Client/ApiTest.php | 18 ++++-- tests/Unit/Reindexer/Entities/IndexTest.php | 39 ++++++++---- tests/Unit/Reindexer/ResponseTest.php | 18 ++++-- .../Reindexer/Services/NamespacesTest.php | 27 +++++--- 25 files changed, 296 insertions(+), 149 deletions(-) diff --git a/examples/common-part.php b/examples/common-part.php index 6c3b0b3..a597fed 100644 --- a/examples/common-part.php +++ b/examples/common-part.php @@ -4,15 +4,18 @@ use Reindexer\LoggerInterface; use Reindexer\Response; -class Configuration { +class Configuration +{ protected $api; protected $config; - public function __construct(array $config = []) { + public function __construct(array $config = []) + { $this->config = $config; } - public function getApi(): Api { + public function getApi(): Api + { if (empty($this->api)) { $this->api = new Api($this->config['endpoint'], $this->config['client_config']); $this->api->setLogger(new ApiLogger()); @@ -22,8 +25,10 @@ public function getApi(): Api { } } -class ApiLogger implements LoggerInterface { - public function logResponse(Response $response): void { +class ApiLogger implements LoggerInterface +{ + public function logResponse(Response $response): void + { echo sprintf( '==== api request info ===='.PHP_EOL. 'Content-Type: %s'.PHP_EOL. diff --git a/examples/config.json b/examples/config.json index ffd17e2..2718eb4 100644 --- a/examples/config.json +++ b/examples/config.json @@ -1,6 +1,6 @@ { - "endpoint": "http://localhost:9088", + "endpoint": "http://reindexer:9088", "client_config": { "http_errors": 0 } -} \ No newline at end of file +} diff --git a/src/Reindexer/BaseService.php b/src/Reindexer/BaseService.php index 0f66d05..d6b1e75 100644 --- a/src/Reindexer/BaseService.php +++ b/src/Reindexer/BaseService.php @@ -4,7 +4,8 @@ use Reindexer\Client\BaseApi; -abstract class BaseService { +abstract class BaseService +{ protected BaseApi $client; protected string $version = 'v1'; protected $mapJsonFields = []; @@ -13,23 +14,27 @@ abstract class BaseService { 'Content-Type' => 'application/json;charset=utf-8' ]; - public function __construct(BaseApi $client) { + public function __construct(BaseApi $client) + { $this->client = $client; } - public function setVersion(string $version): self { + public function setVersion(string $version): self + { $this->version = $version; return $this; } - public function setHeaders(array $headers): self { + public function setHeaders(array $headers): self + { $this->defaultHeaders = $headers; return $this; } - public function addHeaders(array $headers): self { + public function addHeaders(array $headers): self + { $this->defaultHeaders = array_merge($this->defaultHeaders, $headers); return $this; diff --git a/src/Reindexer/Client/Api.php b/src/Reindexer/Client/Api.php index b275a1d..df645da 100644 --- a/src/Reindexer/Client/Api.php +++ b/src/Reindexer/Client/Api.php @@ -10,30 +10,36 @@ use Reindexer\LoggerInterface; use Reindexer\Response; -class Api extends BaseApi { +class Api extends BaseApi +{ protected $client; protected $info; protected $logger; protected $error; - public function __construct(string $host, array $config = []) { + public function __construct(string $host, array $config = []) + { parent::__construct($host); $this->client = new Client($config); } - public function setLogger(LoggerInterface $logger): void { + public function setLogger(LoggerInterface $logger): void + { $this->logger = $logger; } - public function getClient(): Client { + public function getClient(): Client + { return $this->client; } - public function setClient(Client $client): void { + public function setClient(Client $client): void + { $this->client = $client; } - public function request(string $method, string $uri, string $body = null, array $headers = []): Response { + public function request(string $method, string $uri, string $body = null, array $headers = []): Response + { $instance = $this; $request = new Request($method, $this->host . $uri, $headers); diff --git a/src/Reindexer/Client/BaseApi.php b/src/Reindexer/Client/BaseApi.php index 53e15c7..1ecbced 100644 --- a/src/Reindexer/Client/BaseApi.php +++ b/src/Reindexer/Client/BaseApi.php @@ -4,20 +4,24 @@ use Reindexer\Response; -abstract class BaseApi { +abstract class BaseApi +{ protected $host; protected $config; - public function __construct(string $host, array $config = []) { + public function __construct(string $host, array $config = []) + { $this->host = $host; $this->config = $config; } - public function getHost(): string { + public function getHost(): string + { return $this->host; } - public function setHost(string $host) { + public function setHost(string $host) + { $this->host = $host; } diff --git a/src/Reindexer/Entities/Entity.php b/src/Reindexer/Entities/Entity.php index d93c9a3..724be3b 100644 --- a/src/Reindexer/Entities/Entity.php +++ b/src/Reindexer/Entities/Entity.php @@ -4,12 +4,15 @@ use \ReflectionProperty; -abstract class Entity { - public function getBody(): array { +abstract class Entity +{ + public function getBody(): array + { return $this->parseValue($this); } - protected function parseValue($instance): array { + protected function parseValue($instance): array + { $result = []; $reflectionClass = new \ReflectionClass($instance); $properties = $reflectionClass->getProperties(ReflectionProperty::IS_PRIVATE); diff --git a/src/Reindexer/Entities/Index.php b/src/Reindexer/Entities/Index.php index 81b72e3..066786e 100644 --- a/src/Reindexer/Entities/Index.php +++ b/src/Reindexer/Entities/Index.php @@ -2,7 +2,8 @@ namespace Reindexer\Entities; -class Index extends Entity { +class Index extends Entity +{ private $name; private $jsonPaths; private $fieldType; @@ -27,101 +28,121 @@ class Index extends Entity { 'sortOrderLetters' => 'sort_order_letters', ]; - public function getName() { + public function getName() + { return $this->name; } - public function setName(string $name) { + public function setName(string $name) + { $this->name = $name; return $this; } - public function getJsonPaths(): array { + public function getJsonPaths(): array + { return $this->jsonPaths ?? []; } - public function setJsonPaths(array $jsonPaths): self { + public function setJsonPaths(array $jsonPaths): self + { $this->jsonPaths = $jsonPaths; return $this; } - public function getFieldType(): string { + public function getFieldType(): string + { return $this->fieldType; } - public function setFieldType($fieldType): self { + public function setFieldType($fieldType): self + { $this->fieldType = $fieldType; return $this; } - public function isPk() { + public function isPk() + { return $this->isPk; } - public function setIsPk(bool $isPk) { + public function setIsPk(bool $isPk) + { $this->isPk = $isPk; return $this; } - public function isArray(): bool { + public function isArray(): bool + { return $this->isArray; } - public function setIsArray(bool $isArray): self { + public function setIsArray(bool $isArray): self + { $this->isArray = $isArray; return $this; } - public function isDense(): bool { + public function isDense(): bool + { return $this->isDense; } - public function setIsDense(bool $isDense): self { + public function setIsDense(bool $isDense): self + { $this->isDense = $isDense; return $this; } - public function isAppendable(): bool { + public function isAppendable(): bool + { return $this->isAppendable; } - public function setIsAppendable(bool $isAppendable): self { + public function setIsAppendable(bool $isAppendable): self + { $this->isAppendable = $isAppendable; return $this; } - public function getCollateMode(): string { + public function getCollateMode(): string + { return $this->collateMode; } - public function setCollateMode(string $collateMode): self { + public function setCollateMode(string $collateMode): self + { $this->collateMode = $collateMode; return $this; } - public function getSortOrderLetters(): string { + public function getSortOrderLetters(): string + { return $this->sortOrderLetters; } - public function setSortOrderLetters(string $sortOrderLetters): self { + public function setSortOrderLetters(string $sortOrderLetters): self + { $this->sortOrderLetters = $sortOrderLetters; return $this; } - public function getIndexType(): string { + public function getIndexType(): string + { return $this->indexType; } - public function setIndexType(string $indexType): self { + public function setIndexType(string $indexType): self + { $this->indexType = $indexType; return $this; diff --git a/src/Reindexer/Entities/SdlQuery.php b/src/Reindexer/Entities/SdlQuery.php index e18545c..b70e06b 100644 --- a/src/Reindexer/Entities/SdlQuery.php +++ b/src/Reindexer/Entities/SdlQuery.php @@ -2,7 +2,8 @@ namespace Reindexer\Entities; -class SdlQuery extends Entity { +class SdlQuery extends Entity +{ protected $namespace; protected $limit; protected $offset; diff --git a/src/Reindexer/Enum/CollateMode.php b/src/Reindexer/Enum/CollateMode.php index 6665e9d..326b075 100644 --- a/src/Reindexer/Enum/CollateMode.php +++ b/src/Reindexer/Enum/CollateMode.php @@ -2,7 +2,8 @@ namespace Reindexer\Enum; -class CollateMode { +class CollateMode +{ const NONE = 'none'; const ASCII = 'ascii'; const UTF8 = 'utf8'; diff --git a/src/Reindexer/Enum/FieldType.php b/src/Reindexer/Enum/FieldType.php index 72fed10..902ab52 100644 --- a/src/Reindexer/Enum/FieldType.php +++ b/src/Reindexer/Enum/FieldType.php @@ -2,7 +2,8 @@ namespace Reindexer\Enum; -class FieldType { +class FieldType +{ const INT = 'int'; const INT64 = 'int64'; const DOUBLE = 'double'; diff --git a/src/Reindexer/Enum/IndexType.php b/src/Reindexer/Enum/IndexType.php index 86119be..626e804 100644 --- a/src/Reindexer/Enum/IndexType.php +++ b/src/Reindexer/Enum/IndexType.php @@ -2,7 +2,8 @@ namespace Reindexer\Enum; -class IndexType { +class IndexType +{ const HASH = 'hash'; const TREE = 'tree'; const TEXT = 'text'; diff --git a/src/Reindexer/LoggerInterface.php b/src/Reindexer/LoggerInterface.php index f0150d6..8f1f9db 100644 --- a/src/Reindexer/LoggerInterface.php +++ b/src/Reindexer/LoggerInterface.php @@ -2,6 +2,7 @@ namespace Reindexer; -interface LoggerInterface { +interface LoggerInterface +{ public function logResponse(Response $response); } diff --git a/src/Reindexer/Response.php b/src/Reindexer/Response.php index 90f215c..d62abfa 100644 --- a/src/Reindexer/Response.php +++ b/src/Reindexer/Response.php @@ -6,52 +6,62 @@ use GuzzleHttp\Psr7\Response as ResponseInterface; use Psr\Http\Message\StreamInterface; -class Response { +class Response +{ protected $response; protected $responseContents = ''; protected $request; protected $info; protected $error; - public function setRequest(Request $request): self { + public function setRequest(Request $request): self + { $this->request = $request; return $this; } - public function getRequest(): Request { + public function getRequest(): Request + { return $this->request; } - public function setResponse(ResponseInterface $response): self { + public function setResponse(ResponseInterface $response): self + { $this->response = $response; return $this; } - public function getResponse() : ResponseInterface { + public function getResponse() : ResponseInterface + { return $this->response; } - public function getRequestHeaders(): array { + public function getRequestHeaders(): array + { return $this->getRequest()->getHeaders(); } - public function getResponseHeaders(): array { + public function getResponseHeaders(): array + { return $this->getResponse()->getHeaders(); } - public function getInfo(): array { + public function getInfo(): array + { return $this->info; } - public function setInfo(array $info): self { + public function setInfo(array $info): self + { $this->info = $info; return $this; } - public function getResponseBody(): string { + public function getResponseBody(): string + { if (empty($this->responseContents)) { $stream = $this->getResponse()->getBody(); $this->responseContents = $this->getContentsFromStream($stream); @@ -60,31 +70,37 @@ public function getResponseBody(): string { return $this->responseContents; } - private function getContentsFromStream(StreamInterface $stream): string { + private function getContentsFromStream(StreamInterface $stream): string + { $stream->rewind(); return $stream->getContents(); } - public function getDecodedResponseBody(bool $isAssoc = false): mixed { + public function getDecodedResponseBody(bool $isAssoc = false): mixed + { return json_decode($this->getResponseBody(), $isAssoc) ?? []; } - public function getError(): string { + public function getError(): string + { return $this->error ?? ''; } - public function setError(?string $error): self { + public function setError(?string $error): self + { $this->error = $error; return $this; } - public function getCode(): int { + public function getCode(): int + { return $this->getInfo()['http_code'] ?? $this->getResponse()->getStatusCode() ?? 0; } - public function getRequestParams(): string { + public function getRequestParams(): string + { return $this->getRequest()->getBody()->__toString(); } } diff --git a/src/Reindexer/Services/Database.php b/src/Reindexer/Services/Database.php index a3c413c..c17ee8e 100644 --- a/src/Reindexer/Services/Database.php +++ b/src/Reindexer/Services/Database.php @@ -5,8 +5,10 @@ use Reindexer\BaseService; use Reindexer\Response; -class Database extends BaseService { - public function create(string $name): Response { +class Database extends BaseService +{ + public function create(string $name): Response + { $uri = sprintf('/api/%s/db', $this->version); return $this->client->request( 'POST', @@ -18,7 +20,8 @@ public function create(string $name): Response { ); } - public function getList(): Response { + public function getList(): Response + { $uri = sprintf('/api/%s/db', $this->version); return $this->client->request( @@ -29,7 +32,8 @@ public function getList(): Response { ); } - public function drop(string $name): Response { + public function drop(string $name): Response + { $uri = sprintf('/api/%s/db/%s', $this->version, $name); return $this->client->request( 'DELETE', diff --git a/src/Reindexer/Services/Index.php b/src/Reindexer/Services/Index.php index 8d3ff51..e8be120 100644 --- a/src/Reindexer/Services/Index.php +++ b/src/Reindexer/Services/Index.php @@ -5,8 +5,10 @@ use Reindexer\BaseService; use Reindexer\Entities\Index as IndexEntity; -class Index extends BaseService { - public function create(IndexEntity $index, string $database, string $namespace) { +class Index extends BaseService +{ + public function create(IndexEntity $index, string $database, string $namespace) + { $uri = sprintf( '/api/%s/db/%s/namespaces/%s/indexes', $this->version, @@ -22,7 +24,8 @@ public function create(IndexEntity $index, string $database, string $namespace) ); } - public function get(string $database, string $namespace) { + public function get(string $database, string $namespace) + { $uri = sprintf( '/api/%s/db/%s/namespaces/%s/indexes', $this->version, @@ -38,7 +41,8 @@ public function get(string $database, string $namespace) { ); } - public function delete(string $database, string $namespace, string $name) { + public function delete(string $database, string $namespace, string $name) + { $uri = sprintf( '/api/%s/db/%s/namespaces/%s/indexes/%s', $this->version, diff --git a/src/Reindexer/Services/Item.php b/src/Reindexer/Services/Item.php index 8735777..5488998 100644 --- a/src/Reindexer/Services/Item.php +++ b/src/Reindexer/Services/Item.php @@ -4,27 +4,33 @@ use Reindexer\BaseService; -class Item extends BaseService { +class Item extends BaseService +{ protected string $database; protected string $namespace; - public function getDatabase(): string { + public function getDatabase(): string + { return $this->database ?? ''; } - public function setDatabase(string $database): void { + public function setDatabase(string $database): void + { $this->database = $database; } - public function getNamespace(): string { + public function getNamespace(): string + { return $this->namespace ?? ''; } - public function setNamespace(string $namespace): void { + public function setNamespace(string $namespace): void + { $this->namespace = $namespace; } - public function add(array $data = []) { + public function add(array $data = []) + { $uri = sprintf( '/api/%s/db/%s/namespaces/%s/items', $this->version, @@ -40,7 +46,8 @@ public function add(array $data = []) { ); } - public function update(array $data = []) { + public function update(array $data = []) + { $uri = sprintf( '/api/%s/db/%s/namespaces/%s/items', $this->version, @@ -56,7 +63,8 @@ public function update(array $data = []) { ); } - public function delete(array $data = []) { + public function delete(array $data = []) + { $uri = sprintf( '/api/%s/db/%s/namespaces/%s/items', $this->version, @@ -72,7 +80,8 @@ public function delete(array $data = []) { ); } - public function get(int $limit = 0, int $offset = 0, string $sortField = '', string $sortOrder = '') { + public function get(int $limit = 0, int $offset = 0, string $sortField = '', string $sortOrder = '') + { $uri = sprintf( '/api/%s/db/%s/namespaces/%s/items', $this->version, diff --git a/src/Reindexer/Services/Namespaces.php b/src/Reindexer/Services/Namespaces.php index dc9da2f..7907eae 100644 --- a/src/Reindexer/Services/Namespaces.php +++ b/src/Reindexer/Services/Namespaces.php @@ -7,18 +7,22 @@ use Reindexer\Entities\Index as IndexEntity; use Reindexer\Response; -class Namespaces extends BaseService { +class Namespaces extends BaseService +{ protected string $database; - public function getDatabase(): string { + public function getDatabase(): string + { return $this->database ?? ''; } - public function setDatabase(string $database): void { + public function setDatabase(string $database): void + { $this->database = $database; } - public function getList(string $sortOrder = 'asc'): Response { + public function getList(string $sortOrder = 'asc'): Response + { $uri = sprintf( '/api/%s/db/%s/namespaces', $this->version, @@ -37,7 +41,8 @@ public function getList(string $sortOrder = 'asc'): Response { ); } - public function create(string $name, array $indexes = []): Response { + public function create(string $name, array $indexes = []): Response + { $body = [ 'name' => $name, 'storage' => [ @@ -65,7 +70,8 @@ public function create(string $name, array $indexes = []): Response { ); } - public function drop(string $name): Response { + public function drop(string $name): Response + { $uri = sprintf( '/api/%s/db/%s/namespaces/%s', $this->version, @@ -81,7 +87,8 @@ public function drop(string $name): Response { ); } - public function get(string $name): Response { + public function get(string $name): Response + { $uri = sprintf( '/api/%s/db/%s/namespaces/%s', $this->version, @@ -97,7 +104,8 @@ public function get(string $name): Response { ); } - public function truncate(string $name): Response { + public function truncate(string $name): Response + { $uri = sprintf( '/api/%s/db/%s/namespaces/%s/truncate', $this->version, @@ -113,7 +121,8 @@ public function truncate(string $name): Response { ); } - public function rename(string $oldName, string $newName): Response { + public function rename(string $oldName, string $newName): Response + { $uri = sprintf( '/api/%s/db/%s/namespaces/%s/rename/%s', $this->version, @@ -172,7 +181,8 @@ public function getMetaList( ); } - public function addMetaDataKey(string $name, string $key, string $value): Response { + public function addMetaDataKey(string $name, string $key, string $value): Response + { $uri = new Uri( sprintf( '/api/%s/db/%s/namespaces/%s/metabykey', @@ -190,7 +200,8 @@ public function addMetaDataKey(string $name, string $key, string $value): Respon ); } - public function getMetaDataKey(string $name, string $key): Response { + public function getMetaDataKey(string $name, string $key): Response + { $uri = new Uri( sprintf( '/api/%s/db/%s/namespaces/%s/metabykey/%s', diff --git a/src/Reindexer/Services/Query.php b/src/Reindexer/Services/Query.php index 295d9a3..9746c37 100644 --- a/src/Reindexer/Services/Query.php +++ b/src/Reindexer/Services/Query.php @@ -4,18 +4,22 @@ use Reindexer\BaseService; -class Query extends BaseService { +class Query extends BaseService +{ public string $database; - public function getDatabase(): string { + public function getDatabase(): string + { return $this->database ?? ''; } - public function setDatabase(string $database): void { + public function setDatabase(string $database): void + { $this->database = $database; } - public function createByHttpGet(string $query) { + public function createByHttpGet(string $query) + { $uri = sprintf('/api/%s/db/%s/query?q=%s', $this->version, $this->getDatabase(), urlencode($query)); return $this->client->request( @@ -26,7 +30,8 @@ public function createByHttpGet(string $query) { ); } - public function createSqlQueryByHttpPost(string $query) { + public function createSqlQueryByHttpPost(string $query) + { $uri = sprintf('/api/%s/db/%s/sqlquery', $this->version, $this->getDatabase()); return $this->client->request( @@ -37,7 +42,8 @@ public function createSqlQueryByHttpPost(string $query) { ); } - public function createSdlQueryByHttpPost(string $query) { + public function createSdlQueryByHttpPost(string $query) + { $uri = sprintf('/api/%s/db/%s/query', $this->version, $this->getDatabase()); return $this->client->request( diff --git a/tests/Feature/Reindexer/Fixture/HabrPost.php b/tests/Feature/Reindexer/Fixture/HabrPost.php index a56e303..ad70a34 100644 --- a/tests/Feature/Reindexer/Fixture/HabrPost.php +++ b/tests/Feature/Reindexer/Fixture/HabrPost.php @@ -2,7 +2,8 @@ namespace Tests\Feature\Reindexer\Fixture; -class HabrPost { +class HabrPost +{ public const DATA = [ [ 'link' => 'https://habr.com/en/post/448530/', diff --git a/tests/Feature/Reindexer/ServiceTest.php b/tests/Feature/Reindexer/ServiceTest.php index 761ac64..e9ee427 100644 --- a/tests/Feature/Reindexer/ServiceTest.php +++ b/tests/Feature/Reindexer/ServiceTest.php @@ -13,7 +13,8 @@ use Tests\Feature\Reindexer\Fixture\HabrPost; use Tests\Unit\Reindexer\BaseTest; -class ServiceTest extends BaseTest { +class ServiceTest extends BaseTest +{ private string $namespaceName = 'unittests_ns'; private string $database = 'unittests'; private Namespaces $nsService; @@ -23,7 +24,8 @@ class ServiceTest extends BaseTest { private Query $queryService; private Item $itemService; - public function setUp(): void { + public function setUp(): void + { $host = getenv('REINDEXER_HOST'); $this->config = [ 'host' => $host @@ -42,11 +44,13 @@ public function setUp(): void { $this->nsService->create($this->namespaceName); } - public function tearDown(): void { + public function tearDown(): void + { $this->dbService->drop($this->database); } - public function testCreateAndDropDatabase() { + public function testCreateAndDropDatabase() + { $response = $this->dbService->create('unittests_2'); $this->assertSame( [ @@ -61,7 +65,8 @@ public function testCreateAndDropDatabase() { $this->assertEquals(1, count($databases['items'])); } - public function testCreateIndexes() { + public function testCreateIndexes() + { $indexId = (new Index()) ->setCollateMode('none') ->setName('id') @@ -81,7 +86,8 @@ public function testCreateIndexes() { $this->assertEquals($indexId->getCollateMode(), $body['items'][0]['collate_mode']); } - public function testQuery() { + public function testQuery() + { $items = HabrPost::DATA; $indexLink = (new Index()) ->setCollateMode('none') @@ -125,7 +131,8 @@ public function testQuery() { } - public function testAddHeaders() { + public function testAddHeaders() + { $headers = ['User-Agent' => 'reindexer-php-client']; $this->dbService->addHeaders($headers); $response = $this->dbService->create('unittests_3'); @@ -145,7 +152,8 @@ public function testAddHeaders() { $this->assertCount(3, $response->getRequestHeaders()); } - public function testSetHeaders() { + public function testSetHeaders() + { $headers = ['User-Agent' => 'reindexer-php-client']; $this->dbService->setHeaders($headers); $response = $this->dbService->create('unittests_4'); diff --git a/tests/Unit/Reindexer/BaseTest.php b/tests/Unit/Reindexer/BaseTest.php index 82bde32..1200e21 100644 --- a/tests/Unit/Reindexer/BaseTest.php +++ b/tests/Unit/Reindexer/BaseTest.php @@ -9,29 +9,34 @@ use Reindexer\Client\Api; use Reindexer\Response; -abstract class BaseTest extends TestCase { - public function createApiMock(array $methods) { +abstract class BaseTest extends TestCase +{ + public function createApiMock(array $methods) + { return $this->getMockBuilder(Api::class) ->disableOriginalConstructor() ->onlyMethods($methods) ->getMock(); } - public function createApiResponseMock(array $methods) { + public function createApiResponseMock(array $methods) + { return $this->getMockBuilder(Response::class) ->disableOriginalConstructor() ->onlyMethods($methods) ->getMock(); } - public function createGuzzleClient(string $baseUri, array $queue = []) { + public function createGuzzleClient(string $baseUri, array $queue = []) + { return new Client([ 'handler' => new MockHandler($queue), 'base_uri' => $baseUri, ]); } - protected function getContentsFromStream(StreamInterface $stream): string { + protected function getContentsFromStream(StreamInterface $stream): string + { $stream->rewind(); return $stream->getContents(); diff --git a/tests/Unit/Reindexer/Client/ApiTest.php b/tests/Unit/Reindexer/Client/ApiTest.php index f7383d7..99ca081 100644 --- a/tests/Unit/Reindexer/Client/ApiTest.php +++ b/tests/Unit/Reindexer/Client/ApiTest.php @@ -7,29 +7,35 @@ use Reindexer\Client\Api; use Tests\Unit\Reindexer\BaseTest; -class ApiTest extends BaseTest { - public function setUp(): void { +class ApiTest extends BaseTest +{ + public function setUp(): void + { $this->config = [ 'host' => 'http://reindexer:9800' ]; $this->api = new Api($this->config['host']); } - public function testGetHost() { + public function testGetHost() + { $this->api->setHost('reindexer2:9800'); $this->assertEquals('reindexer2:9800', $this->api->getHost()); } - public function testCreateApiInstanceThrowExceptionIfHostEmpty() { + public function testCreateApiInstanceThrowExceptionIfHostEmpty() + { $this->expectException(\TypeError::class); $api = new Api(null); } - public function testGetClient() { + public function testGetClient() + { $this->assertInstanceOf(Client::class, $this->api->getClient()); } - public function testRequest() { + public function testRequest() + { $expectedResponse = new Response( 200, [ diff --git a/tests/Unit/Reindexer/Entities/IndexTest.php b/tests/Unit/Reindexer/Entities/IndexTest.php index cab8708..e2f76e1 100644 --- a/tests/Unit/Reindexer/Entities/IndexTest.php +++ b/tests/Unit/Reindexer/Entities/IndexTest.php @@ -8,67 +8,80 @@ use Reindexer\Enum\IndexType; use Tests\Unit\Reindexer\BaseTest; -class IndexTest extends BaseTest { +class IndexTest extends BaseTest +{ protected $index; protected $client; - public function setUp(): void { + public function setUp(): void + { $this->client = $this->createMock(Api::class); $this->index = new Index($this->client); } - public function testGetAndSetIsDense() { + public function testGetAndSetIsDense() + { $this->index->setIsDense(true); $this->assertTrue($this->index->isDense()); $this->index->setIsDense(false); $this->assertFalse($this->index->isDense()); } - public function testGetAndSetName() { + public function testGetAndSetName() + { $this->index->setName('index_name'); $this->assertEquals('index_name', $this->index->getName()); } - public function testGetAndSetIsPk() { + public function testGetAndSetIsPk() + { $this->index->setIsPk(true); $this->assertTrue($this->index->isPk()); } - public function testGetAndSetFieldType() { + public function testGetAndSetFieldType() + { $this->index->setFieldType(FieldType::INT); $this->assertEquals(FieldType::INT, $this->index->getFieldType()); } - public function testGetAndSetSortOrderLetters() { + public function testGetAndSetSortOrderLetters() + { $this->index->setSortOrderLetters('asc'); $this->assertEquals('asc', $this->index->getSortOrderLetters()); } - public function testGetAndSetIsArray() { + public function testGetAndSetIsArray() + { $this->index->setIsArray(false); $this->assertFalse($this->index->isArray()); } - public function testGetAndSetCollateMode() { + public function testGetAndSetCollateMode() + { $this->index->setCollateMode('none'); $this->assertEquals('none', $this->index->getCollateMode()); } - public function testGetAndSetJsonPath() { + public function testGetAndSetJsonPath() + { $this->index->setJsonPaths(['json_path']); $this->assertEquals(['json_path'], $this->index->getJsonPaths()); } - public function testGetSetFieldType() { + public function testGetSetFieldType() + { $this->index->setFieldType(FieldType::DOUBLE); $this->assertEquals(FieldType::DOUBLE, $this->index->getFieldType()); } - public function testGetAndSetIsAppendable() { + public function testGetAndSetIsAppendable() + { $this->index->setIsAppendable(false); $this->assertFalse($this->index->isAppendable()); } - public function testGetAndIndexType() { + public function testGetAndIndexType() + { $this->index->setIndexType(IndexType::HASH); $this->assertEquals(IndexType::HASH, $this->index->getIndexType()); } diff --git a/tests/Unit/Reindexer/ResponseTest.php b/tests/Unit/Reindexer/ResponseTest.php index 7d589d8..d4bcf3b 100644 --- a/tests/Unit/Reindexer/ResponseTest.php +++ b/tests/Unit/Reindexer/ResponseTest.php @@ -6,8 +6,10 @@ use GuzzleHttp\Psr7\Response as GuzzleResponse; use Reindexer\Response; -class ResponseTest extends BaseTest { - public function setUp(): void { +class ResponseTest extends BaseTest +{ + public function setUp(): void + { $this->response = new Response(); $this->info = [ 'http_code' => 200, @@ -18,7 +20,8 @@ public function setUp(): void { /** * @dataProvider responseProvider */ - public function testGetResponseBody($request, $response, $decodedData) { + public function testGetResponseBody($request, $response, $decodedData) + { $this->response->setRequest($request) ->setResponse($response); $this->assertEquals( @@ -35,7 +38,8 @@ public function testGetResponseBody($request, $response, $decodedData) { ); } - public function testGetCode() { + public function testGetCode() + { $this->response->setInfo($this->info); $this->assertEquals($this->info['http_code'], $this->response->getCode()); } @@ -43,7 +47,8 @@ public function testGetCode() { /** * @dataProvider responseProvider */ - public function testGetRequestHeaders($request, $response) { + public function testGetRequestHeaders($request, $response) + { $this->response->setRequest($request) ->setResponse($response); $this->assertEquals( @@ -52,7 +57,8 @@ public function testGetRequestHeaders($request, $response) { ); } - public function responseProvider() { + public function responseProvider() + { return [ [ new Request('GET', 'api/v1/db'), diff --git a/tests/Unit/Reindexer/Services/NamespacesTest.php b/tests/Unit/Reindexer/Services/NamespacesTest.php index 3c4510e..1fd5877 100644 --- a/tests/Unit/Reindexer/Services/NamespacesTest.php +++ b/tests/Unit/Reindexer/Services/NamespacesTest.php @@ -4,24 +4,28 @@ use Reindexer\Services\Namespaces; use Tests\Unit\Reindexer\BaseTest; -class NamespacesTest extends BaseTest { +class NamespacesTest extends BaseTest +{ /** * @var Namespaces */ private $service; - public function setUp(): void { + public function setUp(): void + { $this->api = $this->createApiMock(['request']); $this->service = new Namespaces($this->api); } - public function testGetDatabase() { + public function testGetDatabase() + { $expected = 'database'; $this->service->setDatabase($expected); $this->assertEquals($expected, $this->service->getDatabase()); } - public function testGetList() { + public function testGetList() + { $responseData = [ 'items' => [ [ @@ -42,7 +46,8 @@ public function testGetList() { /** * @covers \Reindexer\Services\Namespaces */ - public function testGet() { + public function testGet() + { $responseData = [ 'name' => 'namespace_one', 'storage' => [ @@ -74,7 +79,8 @@ public function testGet() { $this->assertEquals(json_encode($responseData), $actual->getResponseBody()); } - public function testTruncate() { + public function testTruncate() + { $responseData = [ "success" => true, "response_code" => 0, @@ -87,7 +93,8 @@ public function testTruncate() { $this->assertEquals(json_encode($responseData), $actual->getResponseBody()); } - public function testRename() { + public function testRename() + { $responseData = [ "success" => true, "response_code" => 0, @@ -100,7 +107,8 @@ public function testRename() { $this->assertEquals(json_encode($responseData), $actual->getResponseBody()); } - public function testGetMetaDataKey() { + public function testGetMetaDataKey() + { $responseData = [ "success" => true, "response_code" => 0, @@ -113,7 +121,8 @@ public function testGetMetaDataKey() { $this->assertEquals(json_encode($responseData), $actual->getResponseBody()); } - public function testGetMetaList() { + public function testGetMetaList() + { $responseData = [ "total_items" => 0, "meta" => [],