diff --git a/CHANGELOG.md b/CHANGELOG.md index 5da6127..9a466e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,12 +8,28 @@ The format is based on [Keep a Changelog][keepachangelog] and this project adher ### Added -- Class `ReportMakeParams` to build make-report parameters +- Class `DevPingParams` as parameter to test connection +- Class `DevTokenParams` as parameter to debug token generation +- Class `UserReportMakeParams` to build make-report parameters +- Class `UserParams` as parameter to retrieve information about current user +- Class `UserBalanceParams` as parameter to retrieve balance information +- Class `UserReportTypesParams` as parameter to retrieve report types data +- Class `UserReportsParams` as parameter to get reports list +- Class `UserReportParams` as parameter to get report by unique report ID +- Class `UserReportRefreshParams` as parameter to refresh existing report - Optional parameter `idempotenceKey` for report-make requests ### Changed - Method `ClientInterface::userReportMake` now takes object `ReportMakeParams` as parameter +- Method `ClientInterface::devPing` now takes optional object `DevPingParams` as parameter +- Method `ClientInterface::devToken` now takes object `DevTokenParams` as parameter +- Method `ClientInterface::user` now takes optional object `UserParams` as parameter +- Method `ClientInterface::userBalance` now takes object `UserBalanceParams` as parameter +- Method `ClientInterface::userReportTypes` now takes optional object `UserReportTypesParams` as parameter +- Method `ClientInterface::userReports` now takes optional object `UserReportsParams` as parameter +- Method `ClientInterface::userReport` now takes object `UserReportParams` as parameter +- Method `ClientInterface::userReportRefresh` now takes object `UserReportRefreshParams` as parameter ### Fixed diff --git a/README.md b/README.md index 0f0edfb..5fd5d05 100644 --- a/README.md +++ b/README.md @@ -52,33 +52,31 @@ And then we can make next operations _(each call will returns an object with ser devPing(); +$client->devPing(new \Avtocod\B2BApi\Params\DevPingParams); // Debug token generation -$client->devToken('username', 'password'); +$client->devToken(new \Avtocod\B2BApi\Params\DevTokenParams('username', 'password')); // Retrieve information about current user -$client->user(true); +$client->user(new \Avtocod\B2BApi\Params\UserParams); // Retrieve balance information for report type -$client->userBalance('report_type_uid@domain'); +$client->userBalance(new \Avtocod\B2BApi\Params\UserBalanceParams('report_type_uid@domain')); // Retrieve report types data -$client->userReportTypes(); +$client->userReportTypes(new \Avtocod\B2BApi\Params\UserReportTypesParams); // Get reports list -$client->userReports(); +$client->userReports(new \Avtocod\B2BApi\Params\UserReportsParams); // Get report by unique report ID -$client->userReport('report_uid_SOMEIDENTIFIERGOESHERE@domain'); +$client->userReport(new \Avtocod\B2BApi\Params\UserReportParams('report_uid_SOMEIDENTIFIERGOESHERE@domain')); // Make (generate) report -$client->userReportMake( - new ReportMakeParams('report_type_uid@domain', 'VIN', 'Z94CB41AAGR323020') -); +$client->userReportMake(new \Avtocod\B2BApi\Params\UserReportMakeParams('report_type_uid@domain', 'VIN', 'Z94CB41AAGR323020')); // Refresh existing report -$client->userReportRefresh('report_uid_SOMEIDENTIFIERGOESHERE@domain'); +$client->userReportRefresh(new \Avtocod\B2BApi\Params\UserReportRefreshParams('report_uid_SOMEIDENTIFIERGOESHERE@domain')); ``` For example, if you want to generate report for `A111AA177` (`GRZ` type), you can: @@ -89,7 +87,7 @@ For example, if you want to generate report for `A111AA177` (`GRZ` type), you ca // Make report (this operation is asynchronous) $report_uid = $client ->userReportMake( - (new ReportMakeParams(`some_report_uid`, 'GRZ', 'A111AA177')) + (new \Avtocod\B2BApi\Params\UserReportMakeParams(`some_report_uid`, 'GRZ', 'A111AA177')) ->setForce(true) ->setOnUpdateUrl('https://example.com/webhook/updated') ->setOnCompleteUrl('https://example.com/webhook/completed') @@ -99,14 +97,15 @@ $report_uid = $client // Wait for report is ready while (true) { - if ($client->userReport($report_uid, false)->first()->isCompleted()) { + $user_report_params = (new \Avtocod\B2BApi\Params\UserReportParams($report_uid))->setIncludeContent(false); + if ($client->userReport($user_report_params)->first()->isCompleted()) { break; } \sleep(1); } -$content = $client->userReport($report_uid)->first()->getContent(); +$content = $client->userReport(new \Avtocod\B2BApi\Params\UserReportParams($report_uid))->first()->getContent(); $vin_code = $content->getByPath('identifiers.vehicle.vin'); // (string) 'JTMHX05J704083922' $engine_kw = $content->getByPath('tech_data.engine.power.kw'); // (int) 227 diff --git a/src/Client.php b/src/Client.php index 081e61b..6faed92 100644 --- a/src/Client.php +++ b/src/Client.php @@ -9,19 +9,27 @@ use GuzzleHttp\Psr7\Request; use PackageVersions\Versions; use GuzzleHttp\Client as Guzzle; +use Avtocod\B2BApi\Params\UserParams; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Avtocod\B2BApi\Params\DevPingParams; +use Avtocod\B2BApi\Params\DevTokenParams; use Avtocod\B2BApi\Responses\UserResponse; use GuzzleHttp\Exception\RequestException; -use Avtocod\B2BApi\Params\ReportMakeParams; +use Avtocod\B2BApi\Params\UserReportParams; use GuzzleHttp\Exception\TransferException; +use Avtocod\B2BApi\Params\UserBalanceParams; +use Avtocod\B2BApi\Params\UserReportsParams; use Avtocod\B2BApi\Responses\DevPingResponse; use Avtocod\B2BApi\Responses\DevTokenResponse; +use Avtocod\B2BApi\Params\UserReportMakeParams; use GuzzleHttp\RequestOptions as GuzzleOptions; +use Avtocod\B2BApi\Params\UserReportTypesParams; use Avtocod\B2BApi\Responses\UserReportResponse; use Avtocod\B2BApi\Responses\UserBalanceResponse; use Avtocod\B2BApi\Responses\UserReportsResponse; use Avtocod\B2BApi\Exceptions\BadRequestException; +use Avtocod\B2BApi\Params\UserReportRefreshParams; use GuzzleHttp\ClientInterface as GuzzleInterface; use Avtocod\B2BApi\Responses\UserReportMakeResponse; use Avtocod\B2BApi\Responses\UserReportTypesResponse; @@ -85,12 +93,14 @@ public function getSettings(): Settings /** * {@inheritdoc} */ - public function devPing(?string $value = null): DevPingResponse + public function devPing(?DevPingParams $params = null): DevPingResponse { return DevPingResponse::fromHttpResponse( $this->doRequest(new Request('get', 'dev/ping'), [ 'query' => [ - 'value' => $value ?? ((string) \time()), + 'value' => $params instanceof DevPingParams && \is_string($value = $params->getValue()) + ? $value + : ((string) \time()), ], ]) ); @@ -117,22 +127,18 @@ public function getVersion(bool $without_hash = true): string /** * {@inheritdoc} */ - public function devToken(string $username, - string $password, - bool $is_hash = false, - ?DateTime $date_from = null, - int $age = 60): DevTokenResponse + public function devToken(DevTokenParams $params): DevTokenResponse { return DevTokenResponse::fromHttpResponse( $this->doRequest(new Request('get', 'dev/token'), [ 'query' => [ - 'user' => $username, - 'pass' => $password, - 'is_hash' => $is_hash + 'user' => $params->getUsername(), + 'pass' => $params->getPassword(), + 'is_hash' => $params->isPasswordHashed() === true ? 'true' : 'false', - 'date' => DateTimeFactory::toIso8601ZuluWithoutMs($date_from ?? new DateTime), - 'age' => \max(1, $age), + 'date' => DateTimeFactory::toIso8601ZuluWithoutMs($params->getDateFrom() ?? new DateTime), + 'age' => \max(1, $params->getTokenLifetime() ?? 60), ], ]) ); @@ -141,12 +147,12 @@ public function devToken(string $username, /** * {@inheritdoc} */ - public function user(bool $detailed = false): UserResponse + public function user(?UserParams $params = null): UserResponse { return UserResponse::fromHttpResponse( $this->doRequest(new Request('get', 'user'), [ 'query' => [ - '_detailed' => $detailed + '_detailed' => $params instanceof UserParams && $params->isDetailed() === true ? 'true' : 'false', ], @@ -157,12 +163,12 @@ public function user(bool $detailed = false): UserResponse /** * {@inheritdoc} */ - public function userBalance(string $report_type_uid, bool $detailed = false): UserBalanceResponse + public function userBalance(UserBalanceParams $params): UserBalanceResponse { return UserBalanceResponse::fromHttpResponse( - $this->doRequest(new Request('get', \sprintf('user/balance/%s', \urlencode($report_type_uid))), [ + $this->doRequest(new Request('get', \sprintf('user/balance/%s', \urlencode($params->getReportTypeUid()))), [ 'query' => [ - '_detailed' => $detailed + '_detailed' => $params->isDetailed() === true ? 'true' : 'false', ], @@ -173,85 +179,127 @@ public function userBalance(string $report_type_uid, bool $detailed = false): Us /** * {@inheritdoc} */ - public function userReportTypes(bool $can_generate = false, - bool $content = false, - string $query = '_all', - int $size = 20, - int $offset = 0, - int $page = 1, - string $sort = '-created_at', - bool $calc_total = false): UserReportTypesResponse + public function userReportTypes(?UserReportTypesParams $params = null): UserReportTypesResponse { + $query = [ + '_can_generate' => 'false', + '_content' => 'false', + '_query' => '_all', + '_size' => 20, + '_offset' => 0, + '_page' => 1, + '_sort' => '-created_at', + '_calc_total' => 'false', + ]; + + // Modify query, if needed + if ($params instanceof UserReportTypesParams) { + if (\is_bool($can_generate = $params->isCanGenerate())) { + $query['_can_generate'] = $can_generate ? 'true' : 'false'; + } + + if (\is_bool($with_content = $params->isWithContent())) { + $query['_content'] = $with_content ? 'true' : 'false'; + } + + if (\is_string($filter_query = $params->getQuery())) { + $query['_query'] = $filter_query; + } + + if (\is_int($per_page = $params->getPerPage())) { + $query['_size'] = \max(1, $per_page); + } + + if (\is_int($offset = $params->getOffset())) { + $query['_offset'] = \max(0, $offset); + } + + if (\is_int($page = $params->getPage())) { + $query['_page'] = \max(1, $page); + } + + if (\is_string($sort_by = $params->getSortBy())) { + $query['_sort'] = $sort_by; + } + + if (\is_bool($is_calc_total = $params->isCalcTotal())) { + $query['_calc_total'] = $is_calc_total ? 'true' : 'false'; + } + } + return UserReportTypesResponse::fromHttpResponse( - $this->doRequest(new Request('get', 'user/report_types'), [ - 'query' => [ - '_can_generate' => $can_generate - ? 'true' - : 'false', - '_content' => $content - ? 'true' - : 'false', - '_query' => $query, - '_size' => \max(1, $size), - '_offset' => \max(0, $offset), - '_page' => \max(1, $page), - '_sort' => $sort, - '_calc_total' => $calc_total - ? 'true' - : 'false', - ], - ]) + $this->doRequest(new Request('get', 'user/report_types'), ['query' => $query]) ); } /** * {@inheritdoc} */ - public function userReports(bool $content = false, - string $query = '_all', - int $size = 20, - int $offset = 0, - int $page = 1, - string $sort = '-created_at', - bool $calc_total = false, - bool $detailed = false): UserReportsResponse + public function userReports(?UserReportsParams $params = null): UserReportsResponse { + $query = [ + '_content' => 'false', + '_query' => '_all', + '_size' => 20, + '_offset' => 0, + '_page' => 1, + '_sort' => '-created_at', + '_calc_total' => 'false', + '_detailed' => 'false', + ]; + + // Modify query, if needed + if ($params instanceof UserReportsParams) { + if (\is_bool($with_content = $params->isWithContent())) { + $query['_content'] = $with_content ? 'true' : 'false'; + } + + if (\is_string($filter_query = $params->getQuery())) { + $query['_query'] = $filter_query; + } + + if (\is_int($per_page = $params->getPerPage())) { + $query['_size'] = \max(1, $per_page); + } + + if (\is_int($offset = $params->getOffset())) { + $query['_offset'] = \max(0, $offset); + } + + if (\is_int($page = $params->getPage())) { + $query['_page'] = \max(1, $page); + } + + if (\is_string($sort_by = $params->getSortBy())) { + $query['_sort'] = $sort_by; + } + + if (\is_bool($is_calc_total = $params->isCalcTotal())) { + $query['_calc_total'] = $is_calc_total ? 'true' : 'false'; + } + + if (\is_bool($is_detailed = $params->isDetailed())) { + $query['_detailed'] = $is_detailed ? 'true' : 'false'; + } + } + return UserReportsResponse::fromHttpResponse( - $this->doRequest(new Request('get', 'user/reports'), [ - 'query' => [ - '_content' => $content - ? 'true' - : 'false', - '_query' => $query, - '_size' => \max(1, $size), - '_offset' => \max(0, $offset), - '_page' => \max(1, $page), - '_sort' => $sort, - '_calc_total' => $calc_total - ? 'true' - : 'false', - '_detailed' => $detailed - ? 'true' - : 'false', - ], - ]) + $this->doRequest(new Request('get', 'user/reports'), ['query' => $query]) ); } /** * {@inheritdoc} */ - public function userReport(string $report_uid, - bool $content = true, - bool $detailed = true): UserReportResponse + public function userReport(UserReportParams $params): UserReportResponse { return UserReportResponse::fromHttpResponse( - $this->doRequest(new Request('get', \sprintf('user/reports/%s', \urlencode($report_uid))), [ + $this->doRequest(new Request('get', \sprintf('user/reports/%s', \urlencode($params->getReportUid()))), [ 'query' => [ - '_content' => $content + '_content' => $params->isIncludeContent() === true || $params->isIncludeContent() === null ? 'true' : 'false', - '_detailed' => $detailed + '_detailed' => $params->isDetailed() === true || $params->isDetailed() === null ? 'true' : 'false', ], @@ -262,7 +310,7 @@ public function userReport(string $report_uid, /** * {@inheritdoc} */ - public function userReportMake(ReportMakeParams $params): UserReportMakeResponse + public function userReportMake(UserReportMakeParams $params): UserReportMakeResponse { $request_body = [ 'queryType' => $params->getType(), @@ -304,11 +352,11 @@ public function userReportMake(ReportMakeParams $params): UserReportMakeResponse /** * {@inheritdoc} */ - public function userReportRefresh(string $report_uid, ?array $options = []): UserReportRefreshResponse + public function userReportRefresh(UserReportRefreshParams $params): UserReportRefreshResponse { return UserReportRefreshResponse::fromHttpResponse( - $this->doRequest(new Request('post', \sprintf('user/reports/%s/_refresh', \urlencode($report_uid))), [ - GuzzleOptions::JSON => (object) ($options ?? []), + $this->doRequest(new Request('post', \sprintf('user/reports/%s/_refresh', \urlencode($params->getReportUid()))), [ + GuzzleOptions::JSON => (object) ($params->getOptions() ?? []), ]) ); } diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 55506a3..d0e787a 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -2,15 +2,22 @@ namespace Avtocod\B2BApi; -use DateTime; +use Avtocod\B2BApi\Params\UserParams; +use Avtocod\B2BApi\Params\DevPingParams; +use Avtocod\B2BApi\Params\DevTokenParams; use Avtocod\B2BApi\Responses\UserResponse; -use Avtocod\B2BApi\Params\ReportMakeParams; +use Avtocod\B2BApi\Params\UserReportParams; +use Avtocod\B2BApi\Params\UserBalanceParams; +use Avtocod\B2BApi\Params\UserReportsParams; use Avtocod\B2BApi\Responses\DevPingResponse; use Avtocod\B2BApi\Responses\DevTokenResponse; +use Avtocod\B2BApi\Params\UserReportMakeParams; +use Avtocod\B2BApi\Params\UserReportTypesParams; use Avtocod\B2BApi\Responses\UserReportResponse; use Avtocod\B2BApi\Responses\UserBalanceResponse; use Avtocod\B2BApi\Responses\UserReportsResponse; use Avtocod\B2BApi\Exceptions\BadRequestException; +use Avtocod\B2BApi\Params\UserReportRefreshParams; use Avtocod\B2BApi\Exceptions\BadResponseException; use Avtocod\B2BApi\Responses\UserReportMakeResponse; use Avtocod\B2BApi\Responses\UserReportTypesResponse; @@ -21,151 +28,108 @@ interface ClientInterface /** * Test connection. * - * @param string|null $value Any string value (server must returns it back) + * @param DevPingParams|null $params * * @throws BadRequestException * @throws BadResponseException * * @return DevPingResponse */ - public function devPing(?string $value = null): DevPingResponse; + public function devPing(?DevPingParams $params = null): DevPingResponse; /** * Debug token generation. * - * @param string $username User identifier (e.g.: `test@test`) - * @param string $password User password - * @param bool $is_hash Password hashed? - * @param DateTime|null $date_from Token availability start date - * @param int $age Token lifetime (in seconds) + * @param DevTokenParams $params * * @throws BadRequestException * @throws BadResponseException * * @return DevTokenResponse */ - public function devToken(string $username, - string $password, - bool $is_hash = false, - ?DateTime $date_from = null, - int $age = 60): DevTokenResponse; + public function devToken(DevTokenParams $params): DevTokenResponse; /** * Retrieve information about current user. * - * @param bool $detailed + * @param UserParams|null $params * * @throws BadRequestException * @throws BadResponseException * * @return UserResponse */ - public function user(bool $detailed = false): UserResponse; + public function user(?UserParams $params = null): UserResponse; /** * Retrieve balance information for report type. * - * @param string $report_type_uid E.g.: `report_type@domain` - * @param bool $detailed + * @param UserBalanceParams $params * * @throws BadRequestException * @throws BadResponseException * * @return UserBalanceResponse */ - public function userBalance(string $report_type_uid, - bool $detailed = false): UserBalanceResponse; + public function userBalance(UserBalanceParams $params): UserBalanceResponse; /** * Retrieve report types data. * - * @param bool $can_generate User nac generate reports for report type? - * @param bool $content Include report content rules - * @param string $query - * @param int $size Maximum entries per page - * @param int $offset Pagination offset - * @param int $page Page number - * @param string $sort Sorting rules - * @param bool $calc_total Calculate total report types count + * @param UserReportTypesParams|null $params * * @throws BadRequestException * @throws BadResponseException * * @return UserReportTypesResponse */ - public function userReportTypes(bool $can_generate = false, - bool $content = false, - string $query = '_all', - int $size = 20, - int $offset = 0, - int $page = 1, - string $sort = '-created_at', - bool $calc_total = false): UserReportTypesResponse; + public function userReportTypes(?UserReportTypesParams $params = null): UserReportTypesResponse; /** * Get reports list. * - * @param bool $content Include reports content into response - * @param string $query - * @param int $size Maximum entries per page - * @param int $offset Pagination offset - * @param int $page Page number - * @param string $sort Sorting rules - * @param bool $calc_total Calculate total reports count - * @param bool $detailed + * @param UserReportsParams|null $params * * @throws BadRequestException * @throws BadResponseException * * @return UserReportsResponse */ - public function userReports(bool $content = false, - string $query = '_all', - int $size = 20, - int $offset = 0, - int $page = 1, - string $sort = '-created_at', - bool $calc_total = false, - bool $detailed = false): UserReportsResponse; + public function userReports(?UserReportsParams $params = null): UserReportsResponse; /** * Get report by unique report ID. * - * @param string $report_uid Report unique ID (e.g.: `some_report_uid_YV1KS9614S107357Y@domain`) - * @param bool $content Include content into response - * @param bool $detailed + * @param UserReportParams $params * * @throws BadRequestException * @throws BadResponseException * * @return UserReportResponse */ - public function userReport(string $report_uid, - bool $content = true, - bool $detailed = true): UserReportResponse; + public function userReport(UserReportParams $params): UserReportResponse; /** * Make report. * - * @param ReportMakeParams $params Object with data to make report + * @param UserReportMakeParams $params Object with data to make report * * @throws BadRequestException * @throws BadResponseException * * @return UserReportMakeResponse */ - public function userReportMake(ReportMakeParams $params): UserReportMakeResponse; + public function userReportMake(UserReportMakeParams $params): UserReportMakeResponse; /** * Refresh existing report. * - * @param string $report_uid Report unique ID (e.g.: `some_report_uid_YV1KS9614S107357Y@domain`) - * @param array|null $options Additional request options + * @param UserReportRefreshParams $params * * @throws BadRequestException * @throws BadResponseException * * @return UserReportRefreshResponse */ - public function userReportRefresh(string $report_uid, ?array $options = []): UserReportRefreshResponse; + public function userReportRefresh(UserReportRefreshParams $params): UserReportRefreshResponse; } diff --git a/src/Params/DevPingParams.php b/src/Params/DevPingParams.php new file mode 100644 index 0000000..1663aba --- /dev/null +++ b/src/Params/DevPingParams.php @@ -0,0 +1,35 @@ +value = $value; + + return $this; + } + + /** + * @return string|null + */ + public function getValue(): ?string + { + return $this->value; + } +} diff --git a/src/Params/DevTokenParams.php b/src/Params/DevTokenParams.php new file mode 100644 index 0000000..245055e --- /dev/null +++ b/src/Params/DevTokenParams.php @@ -0,0 +1,135 @@ +username = $username; + $this->password = $password; + } + + /** + * Get user identifier (e.g.: `test@test`). + * + * @return string + */ + public function getUsername(): string + { + return $this->username; + } + + /** + * Get user password. + * + * @return string|null + */ + public function getPassword(): ?string + { + return $this->password; + } + + /** + * @return bool|null + */ + public function isPasswordHashed(): ?bool + { + return $this->is_password_hashed; + } + + /** + * @param bool $is_password_hashed + * + * @return $this + */ + public function setPasswordHashed(bool $is_password_hashed): self + { + $this->is_password_hashed = $is_password_hashed; + + return $this; + } + + /** + * @return DateTime|null + */ + public function getDateFrom(): ?DateTime + { + return $this->date_from; + } + + /** + * @param DateTime $date_from + * + * @return $this + */ + public function setDateFrom(DateTime $date_from): self + { + $this->date_from = $date_from; + + return $this; + } + + /** + * @return int|null + */ + public function getTokenLifetime(): ?int + { + return $this->token_lifetime; + } + + /** + * @param int $token_lifetime + * + * @return $this + */ + public function setTokenLifetime(int $token_lifetime): self + { + $this->token_lifetime = $token_lifetime; + + return $this; + } +} diff --git a/src/Params/UserBalanceParams.php b/src/Params/UserBalanceParams.php new file mode 100644 index 0000000..153e356 --- /dev/null +++ b/src/Params/UserBalanceParams.php @@ -0,0 +1,60 @@ +report_type_uid = $report_type_uid; + } + + /** + * Get unique report type ID. + * + * @return string + */ + public function getReportTypeUid(): string + { + return $this->report_type_uid; + } + + /** + * @param bool $detailed + * + * @return $this + */ + public function setDetailed(bool $detailed): self + { + $this->detailed = $detailed; + + return $this; + } + + /** + * @return bool|null + */ + public function isDetailed(): ?bool + { + return $this->detailed; + } +} diff --git a/src/Params/UserParams.php b/src/Params/UserParams.php new file mode 100644 index 0000000..accee01 --- /dev/null +++ b/src/Params/UserParams.php @@ -0,0 +1,35 @@ +detailed = $detailed; + + return $this; + } + + /** + * @return bool|null + */ + public function isDetailed(): ?bool + { + return $this->detailed; + } +} diff --git a/src/Params/ReportMakeParams.php b/src/Params/UserReportMakeParams.php similarity index 95% rename from src/Params/ReportMakeParams.php rename to src/Params/UserReportMakeParams.php index 3f2406b..d107e36 100644 --- a/src/Params/ReportMakeParams.php +++ b/src/Params/UserReportMakeParams.php @@ -4,70 +4,70 @@ namespace Avtocod\B2BApi\Params; -final class ReportMakeParams +class UserReportMakeParams { /** * Unique report type ID (e.g.: `some_report_uid` or `some_report_uid@domain`). * * @var string */ - private $report_type_uid; + protected $report_type_uid; /** * Request type (e.g.: `VIN`, `GRZ`, `STS`, `PTS`, `CHASSIS`, etc.). * * @var string */ - private $type; + protected $type; /** * Request body (e.g.: `Z94CB41AAGR323020` (VIN), `А111АА177` (GRZ)). * * @var string */ - private $value; + protected $value; /** * Additional request options. * * @var array>|null */ - private $options; + protected $options; /** * Force update report, if it already was generated previously. * * @var bool|null */ - private $is_force; + protected $is_force; /** * URL to call (using `post` method) when report content updated. * * @var string|null */ - private $on_update_url; + protected $on_update_url; /** * URL to call (using `post` method) when report generation completed. * * @var string|null */ - private $on_complete_url; + protected $on_complete_url; /** * Additional request data. * * @var array>|null */ - private $data; + protected $data; /** * Idempotence key which the server uses to recognize subsequent retries of the same request. * * @var string|null */ - private $idempotence_key; + protected $idempotence_key; /** * ReportMakeParameter constructor. diff --git a/src/Params/UserReportParams.php b/src/Params/UserReportParams.php new file mode 100644 index 0000000..799413d --- /dev/null +++ b/src/Params/UserReportParams.php @@ -0,0 +1,87 @@ +report_uid = $report_uid; + } + + /** + * Get report unique ID. + * + * @return string + */ + public function getReportUid(): string + { + return $this->report_uid; + } + + /** + * @param bool $include_content + * + * @return $this + */ + public function setIncludeContent(bool $include_content): self + { + $this->include_content = $include_content; + + return $this; + } + + /** + * @return bool|null + */ + public function isIncludeContent(): ?bool + { + return $this->include_content; + } + + /** + * @param bool $detailed + * + * @return $this + */ + public function setDetailed(bool $detailed): self + { + $this->detailed = $detailed; + + return $this; + } + + /** + * @return bool|null + */ + public function isDetailed(): ?bool + { + return $this->detailed; + } +} diff --git a/src/Params/UserReportRefreshParams.php b/src/Params/UserReportRefreshParams.php new file mode 100644 index 0000000..dc938af --- /dev/null +++ b/src/Params/UserReportRefreshParams.php @@ -0,0 +1,64 @@ +>|null + */ + protected $options; + + /** + * @param string $report_uid Report unique ID (e.g.: `some_report_uid_YV1KS9614S107357Y@domain`) + */ + public function __construct(string $report_uid) + { + $this->report_uid = $report_uid; + } + + /** + * Get report unique ID. + * + * @return string + */ + public function getReportUid(): string + { + return $this->report_uid; + } + + /** + * Set additional request options. + * + * @param array> $options + * + * @return $this + */ + public function setOptions(array $options): self + { + $this->options = $options; + + return $this; + } + + /** + * Get additional request options. + * + * @return array>|null + */ + public function getOptions(): ?array + { + return $this->options; + } +} diff --git a/src/Params/UserReportTypesParams.php b/src/Params/UserReportTypesParams.php new file mode 100644 index 0000000..86297c2 --- /dev/null +++ b/src/Params/UserReportTypesParams.php @@ -0,0 +1,224 @@ +can_generate = $can_generate; + + return $this; + } + + /** + * @return bool|null + */ + public function isCanGenerate(): ?bool + { + return $this->can_generate; + } + + /** + * @param string $query + * + * @return $this + */ + public function setQuery(string $query): self + { + $this->query = $query; + + return $this; + } + + /** + * @return string|null + */ + public function getQuery(): ?string + { + return $this->query; + } + + /** + * @param int $page + * + * @return $this + */ + public function setPage(int $page): self + { + $this->page = $page; + + return $this; + } + + /** + * @return int|null + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param int $per_page + * + * @return $this + */ + public function setPerPage(int $per_page): self + { + $this->per_page = $per_page; + + return $this; + } + + /** + * @return int|null + */ + public function getPerPage(): ?int + { + return $this->per_page; + } + + /** + * @param int $offset + * + * @return $this + */ + public function setOffset(int $offset): self + { + $this->offset = $offset; + + return $this; + } + + /** + * @return int|null + */ + public function getOffset(): ?int + { + return $this->offset; + } + + /** + * @param string $sort_by + * + * @return $this + */ + public function setSortBy(string $sort_by): self + { + $this->sort_by = $sort_by; + + return $this; + } + + /** + * @return string|null + */ + public function getSortBy(): ?string + { + return $this->sort_by; + } + + /** + * @param bool $with_content + * + * @return $this + */ + public function setWithContent(bool $with_content): self + { + $this->with_content = $with_content; + + return $this; + } + + /** + * @return bool|null + */ + public function isWithContent(): ?bool + { + return $this->with_content; + } + + /** + * @param bool $calc_total + * + * @return $this + */ + public function setCalcTotal(bool $calc_total): self + { + $this->calc_total = $calc_total; + + return $this; + } + + /** + * @return bool|null + */ + public function isCalcTotal(): ?bool + { + return $this->calc_total; + } +} diff --git a/src/Params/UserReportsParams.php b/src/Params/UserReportsParams.php new file mode 100644 index 0000000..2ec31e7 --- /dev/null +++ b/src/Params/UserReportsParams.php @@ -0,0 +1,224 @@ +detailed = $detailed; + + return $this; + } + + /** + * @return bool|null + */ + public function isDetailed(): ?bool + { + return $this->detailed; + } + + /** + * @param string $query + * + * @return $this + */ + public function setQuery(string $query): self + { + $this->query = $query; + + return $this; + } + + /** + * @return string|null + */ + public function getQuery(): ?string + { + return $this->query; + } + + /** + * @param int $page + * + * @return $this + */ + public function setPage(int $page): self + { + $this->page = $page; + + return $this; + } + + /** + * @return int|null + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param int $per_page + * + * @return $this + */ + public function setPerPage(int $per_page): self + { + $this->per_page = $per_page; + + return $this; + } + + /** + * @return int|null + */ + public function getPerPage(): ?int + { + return $this->per_page; + } + + /** + * @param int $offset + * + * @return $this + */ + public function setOffset(int $offset): self + { + $this->offset = $offset; + + return $this; + } + + /** + * @return int|null + */ + public function getOffset(): ?int + { + return $this->offset; + } + + /** + * @param string $sort_by + * + * @return $this + */ + public function setSortBy(string $sort_by): self + { + $this->sort_by = $sort_by; + + return $this; + } + + /** + * @return string|null + */ + public function getSortBy(): ?string + { + return $this->sort_by; + } + + /** + * @param bool $with_content + * + * @return $this + */ + public function setWithContent(bool $with_content): self + { + $this->with_content = $with_content; + + return $this; + } + + /** + * @return bool|null + */ + public function isWithContent(): ?bool + { + return $this->with_content; + } + + /** + * @param bool $calc_total + * + * @return $this + */ + public function setCalcTotal(bool $calc_total): self + { + $this->calc_total = $calc_total; + + return $this; + } + + /** + * @return bool|null + */ + public function isCalcTotal(): ?bool + { + return $this->calc_total; + } +} diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index b1ab924..da29d56 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -4,14 +4,18 @@ namespace Avtocod\B2BApi\Tests\Feature; -use DateTime; use Dotenv\Dotenv; use Avtocod\B2BApi\Client; use Avtocod\B2BApi\Settings; +use Avtocod\B2BApi\Params\DevPingParams; +use Avtocod\B2BApi\Params\DevTokenParams; use Avtocod\B2BApi\Tokens\Auth\AuthToken; use Avtocod\B2BApi\Tests\AbstractTestCase; -use Avtocod\B2BApi\Params\ReportMakeParams; +use Avtocod\B2BApi\Params\UserReportParams; +use Avtocod\B2BApi\Params\UserBalanceParams; use Avtocod\B2BApi\Responses\Entities\Balance; +use Avtocod\B2BApi\Params\UserReportMakeParams; +use Avtocod\B2BApi\Params\UserReportRefreshParams; /** * @coversNothing @@ -65,7 +69,10 @@ protected function setUp(): void */ public function testDevPing(): void { - $this->assertSame($value = 'feature test' . \random_int(1, 9999), $this->client->devPing($value)->getValue()); + $this->assertSame( + $value = 'feature test' . \random_int(1, 9999), + $this->client->devPing((new DevPingParams)->setValue($value))->getValue() + ); } /** @@ -73,11 +80,14 @@ public function testDevPing(): void */ public function testDevToken(): void { - $now = new DateTime; - $age = 60; + // Prepare params to request without domain + $params = new DevTokenParams($this->username, $this->password); + $params + ->setPasswordHashed(false) + ->setDateFrom($now = new \DateTime) + ->setTokenLifetime($age = 60); - // Without domain - $response = $this->client->devToken($this->username, $this->password, false, $now, $age); + $response = $this->client->devToken($params); $this->assertSame($this->username, $response->getUser()); $this->assertSame( @@ -85,8 +95,14 @@ public function testDevToken(): void $response->getToken() ); - // With domain - $response = $this->client->devToken($this->username . '@' . $this->domain, $this->password, false, $now, $age); + // Prepare params to request with domain + $params = new DevTokenParams($this->username . '@' . $this->domain, $this->password); + $params + ->setPasswordHashed(false) + ->setDateFrom($now) + ->setTokenLifetime($age); + + $response = $this->client->devToken($params); $this->assertSame($this->username . '@' . $this->domain, $response->getUser()); $this->assertSame( @@ -113,7 +129,10 @@ public function testUserBalance(): void { $this->assertSame( $this->report_type, - $this->client->userBalance($this->report_type)->getByType(Balance::TOTALLY)->getReportTypeUid() + $this->client + ->userBalance(new UserBalanceParams($this->report_type)) + ->getByType(Balance::TOTALLY) + ->getReportTypeUid() ); } @@ -147,9 +166,10 @@ public function testUserReports(): void */ public function testUserReport(): void { - $reports = $this->client->userReports(); + $reports = $this->client->userReports(); + $report_uid = $reports->first()->getUid(); - $report = $this->client->userReport($reports->first()->getUid()); + $report = $this->client->userReport(new UserReportParams($report_uid)); $this->assertSame(1, $report->getSize()); @@ -165,7 +185,7 @@ public function testUserReportMake(): void $this->assertStringContainsString( $vin = 'Z94CB41AAGR323020', $this->client - ->userReportMake((new ReportMakeParams($this->report_type, 'VIN', $vin))->setForce(true)) + ->userReportMake((new UserReportMakeParams($this->report_type, 'VIN', $vin))->setForce(true)) ->first() ->getReportUid() ); @@ -180,7 +200,7 @@ public function testUserReportRefresh(): void { $reports = $this->client->userReports(); $report_uid = $reports->first()->getUid(); - $response = $this->client->userReportRefresh($report_uid); + $response = $this->client->userReportRefresh(new UserReportRefreshParams($report_uid)); $this->assertSame( $report_uid, $response->first()->getReportUid() diff --git a/tests/Unit/ClientTest.php b/tests/Unit/ClientTest.php index f2d2713..801354d 100644 --- a/tests/Unit/ClientTest.php +++ b/tests/Unit/ClientTest.php @@ -15,17 +15,25 @@ use GuzzleHttp\Client as Guzzle; use Avtocod\B2BApi\ClientInterface; use Avtocod\B2BApi\DateTimeFactory; +use Avtocod\B2BApi\Params\UserParams; +use Avtocod\B2BApi\Params\DevPingParams; +use Avtocod\B2BApi\Params\DevTokenParams; use Avtocod\B2BApi\WithSettingsInterface; use Avtocod\B2BApi\Tests\AbstractTestCase; use GuzzleHttp\Exception\ConnectException; -use Avtocod\B2BApi\Params\ReportMakeParams; +use Avtocod\B2BApi\Params\UserReportParams; use Avtocod\B2BApi\Responses\Entities\User; +use Avtocod\B2BApi\Params\UserBalanceParams; +use Avtocod\B2BApi\Params\UserReportsParams; use Avtocod\B2BApi\Events\RequestFailedEvent; use Avtocod\B2BApi\Responses\Entities\Report; use Avtocod\B2BApi\Responses\Entities\Balance; +use Avtocod\B2BApi\Params\UserReportMakeParams; +use Avtocod\B2BApi\Params\UserReportTypesParams; use Avtocod\B2BApi\Responses\Entities\ReportMade; use Avtocod\B2BApi\Responses\Entities\ReportType; use Avtocod\B2BApi\Exceptions\BadRequestException; +use Avtocod\B2BApi\Params\UserReportRefreshParams; use Avtocod\B2BApi\Events\AfterRequestSendingEvent; use Avtocod\B2BApi\Exceptions\BadResponseException; use Avtocod\B2BApi\Events\BeforeRequestSendingEvent; @@ -362,7 +370,7 @@ public function testDevPing(): void ) ); - $response = $this->client->devPing($value); + $response = $this->client->devPing((new DevPingParams)->setValue($value)); $this->assertSame($value, $response->getValue()); $this->assertSame($in, $response->getIn()); @@ -425,7 +433,13 @@ public function testDevToken(): void ) ); - $response = $this->client->devToken($user, $pass, $is_hash, $date, $age); + $params = new DevTokenParams($user, $pass); + $params + ->setPasswordHashed($is_hash) + ->setDateFrom($date) + ->setTokenLifetime($age); + + $response = $this->client->devToken($params); $this->assertSame($user, $response->getUser()); $this->assertSame($pass, $response->getPassword()); @@ -465,7 +479,13 @@ public function testDevTokenUsingWrongJson(): void new Response(200, ['content-type' => 'application/json;charset=utf-8'], '{"foo":]') ); - $this->client->devToken($user, $pass, $is_hash, $date, $age); + $params = new DevTokenParams($user, $pass); + $params + ->setPasswordHashed($is_hash) + ->setDateFrom($date) + ->setTokenLifetime($age); + + $this->client->devToken($params); } /** @@ -605,7 +625,7 @@ public function testUserDetailed(): void ) ); - $response = $this->client->user(true); + $response = $this->client->user((new UserParams)->setDetailed(true)); $this->assertSame($state, $response->getState()); $this->assertSame($size, $response->getSize()); @@ -667,7 +687,7 @@ public function testUserUsingWrongJson(): void new Response(200, ['content-type' => 'application/json;charset=utf-8'], '{"foo":]') ); - $this->client->user(true); + $this->client->user((new UserParams)->setDetailed(true)); } /** @@ -716,7 +736,7 @@ public function testUserBalance(): void ) ); - $response = $this->client->userBalance($report_type_uid); + $response = $this->client->userBalance(new UserBalanceParams($report_type_uid)); $this->assertSame($state, $response->getState()); $this->assertSame($size, $response->getSize()); @@ -809,7 +829,7 @@ public function testUserBalanceDetailed(): void ) ); - $response = $this->client->userBalance($report_type_uid, true); + $response = $this->client->userBalance((new UserBalanceParams($report_type_uid))->setDetailed(true)); $this->assertSame($state, $response->getState()); $this->assertSame($size, $response->getSize()); @@ -867,7 +887,7 @@ public function testUserBalanceUsingWrongJson(): void new Response(200, ['content-type' => 'application/json;charset=utf-8'], '{"foo":]') ); - $this->client->userBalance($report_type_uid, true); + $this->client->userBalance((new UserBalanceParams($report_type_uid))->setDetailed(true)); } /** @@ -896,7 +916,18 @@ public function testUserReportTypes(): void ) ); - $response = $this->client->userReportTypes(true, true, '_all', 20, 0, 1, '-created_at', true); + $params = new UserReportTypesParams; + $params + ->setCanGenerate(true) + ->setWithContent(true) + ->setQuery('_all') + ->setPerPage(20) + ->setOffset(0) + ->setPage(1) + ->setSortBy('-created_at') + ->setCalcTotal(true); + + $response = $this->client->userReportTypes($params); $this->assertCount(11, $response->getData()); $this->assertSame(11, $response->getTotal()); @@ -1067,7 +1098,18 @@ public function testUserReports(): void ) ); - $response = $this->client->userReports(true, '_all', 20, 0, 1, '-created_at', true, true); + $params = new UserReportsParams; + $params + ->setWithContent(true) + ->setQuery('_all') + ->setPerPage(20) + ->setOffset(0) + ->setPage(1) + ->setSortBy('-created_at') + ->setCalcTotal(true) + ->setDetailed(true); + + $response = $this->client->userReports($params); $this->assertSame(8007997, $response->getTotal()); $this->assertSame(2, $response->getSize()); @@ -1148,7 +1190,18 @@ public function testUserReportsUsingWrongJson(): void new Response(200, ['content-type' => 'application/json;charset=utf-8'], '{"foo":]') ); - $this->client->userReports(true, '_all', 20, 0, 1, '-created_at', true, true); + $params = new UserReportsParams; + $params + ->setWithContent(true) + ->setQuery('_all') + ->setPerPage(20) + ->setOffset(0) + ->setPage(1) + ->setSortBy('-created_at') + ->setCalcTotal(true) + ->setDetailed(true); + + $this->client->userReports($params); } /** @@ -1246,7 +1299,7 @@ public function testUserReport(): void ) ); - $response = $this->client->userReport($report_uid); + $response = $this->client->userReport(new UserReportParams($report_uid)); $this->assertSame(1, $response->getSize()); $this->assertEquals( @@ -1324,7 +1377,7 @@ public function testUserReportUsingWrongJson(): void new Response(200, ['content-type' => 'application/json;charset=utf-8'], '{"foo":]') ); - $this->client->userReport($report_uid); + $this->client->userReport(new UserReportParams($report_uid)); } /** @@ -1346,7 +1399,7 @@ public function testUserReportMake(): void ) ); - $params = new ReportMakeParams($report_type_uid, $type = 'VIN', $body = 'Z94CB41AAGR323020'); + $params = new UserReportMakeParams($report_type_uid, $type = 'VIN', $body = 'Z94CB41AAGR323020'); $params ->setForce(true) ->setOnUpdateUrl($on_update = $this->faker->url) @@ -1410,7 +1463,7 @@ public function testUserReportMakeUsingWrongJson(): void new Response(200, ['content-type' => 'application/json;charset=utf-8'], '{"foo":]') ); - $params = new ReportMakeParams($report_type_uid, $type = 'VIN', $body = 'Z94CB41AAGR323020'); + $params = new UserReportMakeParams($report_type_uid, $type = 'VIN', $body = 'Z94CB41AAGR323020'); $this->client->userReportMake($params); } @@ -1434,7 +1487,7 @@ public function testUserReportMakeWithIdempotenceKey(): void ) ); - $params = new ReportMakeParams($report_type_uid, $type = 'VIN', $body = 'Z94CB41AAGR323020'); + $params = new UserReportMakeParams($report_type_uid, $type = 'VIN', $body = 'Z94CB41AAGR323020'); $params ->setIdempotenceKey($idempotence_key = $this->faker->word) ->setForce($this->faker->boolean) @@ -1473,7 +1526,7 @@ public function testUserReportRefresh(): void ) ); - $response = $this->client->userReportRefresh($report_uid); + $response = $this->client->userReportRefresh(new UserReportRefreshParams($report_uid)); $this->assertSame(1, $response->getSize()); $this->assertSame('ok', $response->getState()); @@ -1522,6 +1575,6 @@ public function testUserReportRefreshUsingWrongJson(): void new Response(200, ['content-type' => 'application/json;charset=utf-8'], '{"foo":]') ); - $this->client->userReportRefresh($report_uid); + $this->client->userReportRefresh(new UserReportRefreshParams($report_uid)); } } diff --git a/tests/Unit/Params/DevPingParamsTest.php b/tests/Unit/Params/DevPingParamsTest.php new file mode 100644 index 0000000..b56399e --- /dev/null +++ b/tests/Unit/Params/DevPingParamsTest.php @@ -0,0 +1,35 @@ +setValue($ivalue = $this->faker->word); + + $this->assertSame($ivalue, $params->getValue()); + } + + /** + * @return void + */ + public function testNotSettedOptionalProperties(): void + { + $params = new DevPingParams; + + $this->assertNull($params->getValue()); + } +} diff --git a/tests/Unit/Params/DevTokenParamsTest.php b/tests/Unit/Params/DevTokenParamsTest.php new file mode 100644 index 0000000..72a27b4 --- /dev/null +++ b/tests/Unit/Params/DevTokenParamsTest.php @@ -0,0 +1,53 @@ +faker->word, $password = $this->faker->word); + + $this->assertSame($username, $params->getUsername()); + $this->assertSame($password, $params->getPassword()); + } + + /** + * @return void + */ + public function testSettedOptionalProperties(): void + { + $params = new DevTokenParams($this->faker->word, $this->faker->word); + $params + ->setPasswordHashed($is_password_hashed = $this->faker->boolean) + ->setDateFrom($date = new \DateTime) + ->setTokenLifetime($token_lifetime = $this->faker->randomDigitNotNull); + + $this->assertSame($is_password_hashed, $params->isPasswordHashed()); + $this->assertSame($date, $params->getDateFrom()); + $this->assertSame($token_lifetime, $params->getTokenLifetime()); + } + + /** + * @return void + */ + public function testNotSettedOptionalProperties(): void + { + $params = new DevTokenParams($this->faker->word, $this->faker->word); + + $this->assertNull($params->isPasswordHashed()); + $this->assertNull($params->getDateFrom()); + $this->assertNull($params->getTokenLifetime()); + } +} diff --git a/tests/Unit/Params/UserBalanceParamsTest.php b/tests/Unit/Params/UserBalanceParamsTest.php new file mode 100644 index 0000000..3aa7db4 --- /dev/null +++ b/tests/Unit/Params/UserBalanceParamsTest.php @@ -0,0 +1,47 @@ +faker->word + ); + + $this->assertSame($report_type_uid, $params->getReportTypeUid()); + } + + /** + * @return void + */ + public function testSettedOptionalProperties(): void + { + $params = new UserBalanceParams($this->faker->word); + $params->setDetailed($is_detailed = $this->faker->boolean); + + $this->assertSame($is_detailed, $params->isDetailed()); + } + + /** + * @return void + */ + public function testNotSettedOptionalProperties(): void + { + $params = new UserBalanceParams($this->faker->word); + + $this->assertNull($params->isDetailed()); + } +} diff --git a/tests/Unit/Params/UserParamsTest.php b/tests/Unit/Params/UserParamsTest.php new file mode 100644 index 0000000..06a62b3 --- /dev/null +++ b/tests/Unit/Params/UserParamsTest.php @@ -0,0 +1,35 @@ +setDetailed($is_detailed = $this->faker->boolean); + + $this->assertSame($is_detailed, $params->isDetailed()); + } + + /** + * @return void + */ + public function testNotSettedOptionalProperties(): void + { + $params = new UserParams; + + $this->assertNull($params->isDetailed()); + } +} diff --git a/tests/Unit/Params/ReportMakeParamsTest.php b/tests/Unit/Params/UserReportMakeParamsTest.php similarity index 83% rename from tests/Unit/Params/ReportMakeParamsTest.php rename to tests/Unit/Params/UserReportMakeParamsTest.php index 426ff86..d09ead0 100644 --- a/tests/Unit/Params/ReportMakeParamsTest.php +++ b/tests/Unit/Params/UserReportMakeParamsTest.php @@ -5,19 +5,19 @@ namespace Avtocod\B2BApi\Tests\Unit\Params; use Avtocod\B2BApi\Tests\AbstractTestCase; -use Avtocod\B2BApi\Params\ReportMakeParams; +use Avtocod\B2BApi\Params\UserReportMakeParams; /** - * @covers \Avtocod\B2BApi\Params\ReportMakeParams + * @covers \Avtocod\B2BApi\Params\UserReportMakeParams */ -class ReportMakeParamsTest extends AbstractTestCase +class UserReportMakeParamsTest extends AbstractTestCase { /** * @return void */ public function testRequiredProperties(): void { - $params = new ReportMakeParams( + $params = new UserReportMakeParams( $report_type_uid = $this->faker->word, $type = $this->faker->word, $value = $this->faker->word @@ -33,7 +33,7 @@ public function testRequiredProperties(): void */ public function testSettedOptionalProperties(): void { - $params = new ReportMakeParams($this->faker->word, $this->faker->word, $this->faker->word); + $params = new UserReportMakeParams($this->faker->word, $this->faker->word, $this->faker->word); $params ->setOptions([ ($key_one = $this->faker->word) => $this->faker->randomDigitNotNull, @@ -60,7 +60,7 @@ public function testSettedOptionalProperties(): void */ public function testNotSettedOptionalProperties(): void { - $params = new ReportMakeParams($this->faker->word, $this->faker->word, $this->faker->word); + $params = new UserReportMakeParams($this->faker->word, $this->faker->word, $this->faker->word); $this->assertNull($params->isForce()); $this->assertNull($params->getIdempotenceKey()); diff --git a/tests/Unit/Params/UserReportParamsTest.php b/tests/Unit/Params/UserReportParamsTest.php new file mode 100644 index 0000000..47ddd6a --- /dev/null +++ b/tests/Unit/Params/UserReportParamsTest.php @@ -0,0 +1,51 @@ +faker->word + ); + + $this->assertSame($report_uid, $params->getReportUid()); + } + + /** + * @return void + */ + public function testSettedOptionalProperties(): void + { + $params = new UserReportParams($this->faker->word); + $params + ->setIncludeContent($is_include_content = $this->faker->boolean) + ->setDetailed($is_detailed = $this->faker->boolean); + + $this->assertSame($is_include_content, $params->isIncludeContent()); + $this->assertSame($is_detailed, $params->isDetailed()); + } + + /** + * @return void + */ + public function testNotSettedOptionalProperties(): void + { + $params = new UserReportParams($this->faker->word); + + $this->assertNull($params->isIncludeContent()); + $this->assertNull($params->isDetailed()); + } +} diff --git a/tests/Unit/Params/UserReportRefreshParamsTest.php b/tests/Unit/Params/UserReportRefreshParamsTest.php new file mode 100644 index 0000000..92130f5 --- /dev/null +++ b/tests/Unit/Params/UserReportRefreshParamsTest.php @@ -0,0 +1,52 @@ +faker->word + ); + + $this->assertSame($report_uid, $params->getReportUid()); + } + + /** + * @return void + */ + public function testSettedOptionalProperties(): void + { + $params = new UserReportRefreshParams($this->faker->word); + $params + ->setOptions([ + ($key_one = $this->faker->word) => $this->faker->randomDigitNotNull, + ($key_two = $this->faker->word) => $this->faker->word, + ]); + + $this->assertArrayHasKey($key_one, $params->getOptions()); + $this->assertArrayHasKey($key_two, $params->getOptions()); + } + + /** + * @return void + */ + public function testNotSettedOptionalProperties(): void + { + $params = new UserReportRefreshParams($this->faker->word); + + $this->assertNull($params->getOptions()); + } +} diff --git a/tests/Unit/Params/UserReportTypesParamsTest.php b/tests/Unit/Params/UserReportTypesParamsTest.php new file mode 100644 index 0000000..0f5f94a --- /dev/null +++ b/tests/Unit/Params/UserReportTypesParamsTest.php @@ -0,0 +1,57 @@ +setCanGenerate($can_generate = $this->faker->boolean) + ->setQuery($query = $this->faker->word) + ->setPage($page = $this->faker->randomDigitNotNull) + ->setPerPage($per_page = $this->faker->randomDigitNotNull) + ->setOffset($offset = $this->faker->randomDigitNotNull) + ->setSortBy($sort_by = $this->faker->word) + ->setWithContent($include_content = $this->faker->boolean) + ->setCalcTotal($calc_total = $this->faker->boolean); + + $this->assertSame($can_generate, $params->isCanGenerate()); + $this->assertSame($query, $params->getQuery()); + $this->assertSame($page, $params->getPage()); + $this->assertSame($per_page, $params->getPerPage()); + $this->assertSame($offset, $params->getOffset()); + $this->assertSame($sort_by, $params->getSortBy()); + $this->assertSame($include_content, $params->isWithContent()); + $this->assertSame($calc_total, $params->isCalcTotal()); + } + + /** + * @return void + */ + public function testNotSettedOptionalProperties(): void + { + $params = new UserReportTypesParams; + + $this->assertNull($params->isCanGenerate()); + $this->assertNull($params->getQuery()); + $this->assertNull($params->getPage()); + $this->assertNull($params->getPerPage()); + $this->assertNull($params->getOffset()); + $this->assertNull($params->getSortBy()); + $this->assertNull($params->isWithContent()); + $this->assertNull($params->isCalcTotal()); + } +} diff --git a/tests/Unit/Params/UserReportsParamsTest.php b/tests/Unit/Params/UserReportsParamsTest.php new file mode 100644 index 0000000..05687e3 --- /dev/null +++ b/tests/Unit/Params/UserReportsParamsTest.php @@ -0,0 +1,57 @@ +setDetailed($is_detailed = $this->faker->boolean) + ->setQuery($query = $this->faker->word) + ->setPage($page = $this->faker->randomDigitNotNull) + ->setPerPage($per_page = $this->faker->randomDigitNotNull) + ->setOffset($offset = $this->faker->randomDigitNotNull) + ->setSortBy($sort_by = $this->faker->word) + ->setWithContent($include_content = $this->faker->boolean) + ->setCalcTotal($calc_total = $this->faker->boolean); + + $this->assertSame($is_detailed, $params->isDetailed()); + $this->assertSame($query, $params->getQuery()); + $this->assertSame($page, $params->getPage()); + $this->assertSame($per_page, $params->getPerPage()); + $this->assertSame($offset, $params->getOffset()); + $this->assertSame($sort_by, $params->getSortBy()); + $this->assertSame($include_content, $params->isWithContent()); + $this->assertSame($calc_total, $params->isCalcTotal()); + } + + /** + * @return void + */ + public function testNotSettedOptionalProperties(): void + { + $params = new UserReportsParams; + + $this->assertNull($params->isDetailed()); + $this->assertNull($params->getQuery()); + $this->assertNull($params->getPage()); + $this->assertNull($params->getPerPage()); + $this->assertNull($params->getOffset()); + $this->assertNull($params->getSortBy()); + $this->assertNull($params->isWithContent()); + $this->assertNull($params->isCalcTotal()); + } +}