From 9868b17cfc8472937f5ff01863bc569e0c39496f Mon Sep 17 00:00:00 2001 From: Zhuk Sergey Date: Sat, 18 Mar 2017 11:09:57 +0300 Subject: [PATCH 1/3] upd: test coverage config --- phpunit.xml | 18 ++++++++++-------- src/Api/Providers/Core/Provider.php | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 79682783..2409b6b5 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -19,14 +19,16 @@ ./src/ - /src/Api/Providers/Topics.php - /src/Api/Providers/Boards.php - /src/Api/Providers/Comments.php - /src/Api/Providers/Inbox.php - /src/Api/Providers/Pins.php - /src/Api/Providers/Pinners.php - /src/Api/Providers/Interests.php - /src/Api/Providers/User.php + ./src/Api/Providers/Core/EntityProvider.php + ./src/Api/Providers/Topics.php + ./src/Api/Providers/Boards.php + ./src/Api/Providers/Comments.php + ./src/Api/Providers/Inbox.php + ./src/Api/Providers/Pins.php + ./src/Api/Providers/Pinners.php + ./src/Api/Providers/Password.php + ./src/Api/Providers/Interests.php + ./src/Api/Providers/User.php diff --git a/src/Api/Providers/Core/Provider.php b/src/Api/Providers/Core/Provider.php index f9fb23ad..4a8e3b3d 100644 --- a/src/Api/Providers/Core/Provider.php +++ b/src/Api/Providers/Core/Provider.php @@ -121,7 +121,8 @@ public function isLoggedIn() */ protected function paginate($data, $resourceUrl, $limit = Pagination::DEFAULT_LIMIT) { - return $this->paginateCustom(function() use ($data, $resourceUrl) { + return $this + ->paginateCustom(function() use ($data, $resourceUrl) { return $this->get($data, $resourceUrl, true); })->take($limit); } From dde8519e9b156ed0f1d97b6f2f690e763cb7e45e Mon Sep 17 00:00:00 2001 From: Zhuk Sergey Date: Sat, 18 Mar 2017 11:21:05 +0300 Subject: [PATCH 2/3] upd: Provider refactoring --- phpunit.xml | 2 ++ src/Api/Providers/Auth.php | 4 ++-- src/Api/Providers/Core/Provider.php | 14 +++++++------- src/Api/Providers/Password.php | 2 +- src/Api/Providers/Pins.php | 12 ++++++------ src/Api/Traits/HandlesRequest.php | 6 ++---- tests/Bot/ProviderTest.php | 27 +++++---------------------- 7 files changed, 25 insertions(+), 42 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 2409b6b5..ebd811c6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -29,6 +29,8 @@ ./src/Api/Providers/Password.php ./src/Api/Providers/Interests.php ./src/Api/Providers/User.php + ./src/Api/Providers/Auth.php + ./src/Api/Providers/Keywords.php diff --git a/src/Api/Providers/Auth.php b/src/Api/Providers/Auth.php index b47e51e9..12665999 100644 --- a/src/Api/Providers/Auth.php +++ b/src/Api/Providers/Auth.php @@ -176,9 +176,9 @@ protected function processLogin($username, $password) 'password' => $password, ]; - $response = $this->post($credentials, UrlBuilder::RESOURCE_LOGIN, true); + $this->post($credentials, UrlBuilder::RESOURCE_LOGIN); - if ($response->hasErrors()) return false; + if ($this->response->hasErrors()) return false; $this->request->login(); diff --git a/src/Api/Providers/Core/Provider.php b/src/Api/Providers/Core/Provider.php index 4a8e3b3d..edb6771d 100644 --- a/src/Api/Providers/Core/Provider.php +++ b/src/Api/Providers/Core/Provider.php @@ -45,17 +45,16 @@ public function __construct(Request $request, Response $response) * * @param array $requestOptions * @param string $resourceUrl - * @param bool $returnResponse * * @return Response|bool */ - protected function post($requestOptions, $resourceUrl, $returnResponse = false) + protected function post($requestOptions, $resourceUrl) { $postString = Request::createQuery($requestOptions); $this->execute($resourceUrl, $postString); - return $returnResponse ? $this->response : $this->response->isOk(); + return $this->response->isOk(); } @@ -64,10 +63,9 @@ protected function post($requestOptions, $resourceUrl, $returnResponse = false) * * @param array $requestOptions * @param string $resourceUrl - * @param bool $returnResponse * @return array|bool|Response */ - protected function get(array $requestOptions = [], $resourceUrl = '', $returnResponse = false) + protected function get(array $requestOptions = [], $resourceUrl = '') { $query = Request::createQuery( $requestOptions, @@ -76,7 +74,7 @@ protected function get(array $requestOptions = [], $resourceUrl = '', $returnRes $this->execute($resourceUrl . '?' . $query); - return $returnResponse ? $this->response : $this->response->getResponseData(); + return $this->response->getResponseData(); } @@ -123,7 +121,9 @@ protected function paginate($data, $resourceUrl, $limit = Pagination::DEFAULT_LI { return $this ->paginateCustom(function() use ($data, $resourceUrl) { - return $this->get($data, $resourceUrl, true); + $this->get($data, $resourceUrl); + + return $this->response; })->take($limit); } diff --git a/src/Api/Providers/Password.php b/src/Api/Providers/Password.php index 2f773b44..08045cb3 100644 --- a/src/Api/Providers/Password.php +++ b/src/Api/Providers/Password.php @@ -54,7 +54,7 @@ public function reset($link, $newPassword) 'expiration' => $query['e'], ]; - return $this->post($request, UrlBuilder::RESOURCE_RESET_PASSWORD_UPDATE, true); + return $this->post($request, UrlBuilder::RESOURCE_RESET_PASSWORD_UPDATE); } /** diff --git a/src/Api/Providers/Pins.php b/src/Api/Providers/Pins.php index fa1925e9..897d8ba1 100644 --- a/src/Api/Providers/Pins.php +++ b/src/Api/Providers/Pins.php @@ -84,9 +84,9 @@ public function create($imageUrl, $boardId, $description = '', $link = '') 'board_id' => $boardId, ]; - return $this - ->post($requestOptions, UrlBuilder::RESOURCE_CREATE_PIN, true) - ->getResponseData(); + $this->post($requestOptions, UrlBuilder::RESOURCE_CREATE_PIN); + + return $this->response->getResponseData(); } /** @@ -140,9 +140,9 @@ public function repin($repinId, $boardId, $description = '') 'pin_id' => $repinId, ]; - return $this - ->post($requestOptions, UrlBuilder::RESOURCE_REPIN, true) - ->getResponseData(); + $this->post($requestOptions, UrlBuilder::RESOURCE_REPIN); + + return $this->response->getResponseData(); } /** diff --git a/src/Api/Traits/HandlesRequest.php b/src/Api/Traits/HandlesRequest.php index e64a920d..5cdecaee 100644 --- a/src/Api/Traits/HandlesRequest.php +++ b/src/Api/Traits/HandlesRequest.php @@ -11,19 +11,17 @@ trait HandlesRequest * * @param array $requestOptions * @param string $resourceUrl - * @param bool $returnResponse * * @return Response|bool */ - abstract protected function post($requestOptions, $resourceUrl, $returnResponse = false); + abstract protected function post($requestOptions, $resourceUrl); /** * Executes a GET request to Pinterest API. * * @param array $requestOptions * @param string $resourceUrl - * @param bool $returnResponse * @return array|bool|Response */ - abstract protected function get(array $requestOptions = [], $resourceUrl = '', $returnResponse = false); + abstract protected function get(array $requestOptions = [], $resourceUrl = ''); } \ No newline at end of file diff --git a/tests/Bot/ProviderTest.php b/tests/Bot/ProviderTest.php index 6f774a5d..ed2483bf 100644 --- a/tests/Bot/ProviderTest.php +++ b/tests/Bot/ProviderTest.php @@ -67,21 +67,6 @@ public function it_should_clear_response_before_pagination() $provider->dummyPaginate(['test' => 'test'], 'http://example.com')->toArray(); } - /** @test */ - public function it_should_return_response_object_if_required_for_get_request() - { - $provider = $this->makeProvider([]); - - $this->assertInstanceOf(Response::class, $provider->dummyGet(true)); - } - - /** @test */ - public function it_should_return_response_object_if_required_for_post_request() - { - $provider = $this->makeProvider([]); - - $this->assertInstanceOf(Response::class, $provider->dummyPost(true)); - } /** @test */ public function it_should_return_bool_if_required_for_post_request() @@ -90,7 +75,7 @@ public function it_should_return_bool_if_required_for_post_request() $provider = $this->makeProvider($response); - $this->assertTrue($provider->dummyPost(false)); + $this->assertTrue($provider->dummyPost()); } /** @@ -134,20 +119,18 @@ public function dummyPaginate($data, $resourceUrl) } /** - * @param bool $returnResponse * @return array|bool|Response */ - public function dummyGet($returnResponse) + public function dummyGet() { - return $this->get([], '', $returnResponse); + return $this->get([], ''); } /** - * @param bool $returnResponse * @return array|bool|Response */ - public function dummyPost($returnResponse) + public function dummyPost() { - return $this->post([], '', $returnResponse); + return $this->post([], ''); } } \ No newline at end of file From 87868c53542d700c23a45ee50dbcd3e2d2f1da1c Mon Sep 17 00:00:00 2001 From: Zhuk Sergey Date: Sat, 18 Mar 2017 11:23:56 +0300 Subject: [PATCH 3/3] upd: code stye --- src/Api/Providers/Core/Provider.php | 2 +- src/Api/Traits/HandlesRequest.php | 2 +- src/Api/Traits/Searchable.php | 2 +- tests/Bot/ProviderTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Api/Providers/Core/Provider.php b/src/Api/Providers/Core/Provider.php index edb6771d..0f78c54d 100644 --- a/src/Api/Providers/Core/Provider.php +++ b/src/Api/Providers/Core/Provider.php @@ -120,7 +120,7 @@ public function isLoggedIn() protected function paginate($data, $resourceUrl, $limit = Pagination::DEFAULT_LIMIT) { return $this - ->paginateCustom(function() use ($data, $resourceUrl) { + ->paginateCustom(function () use ($data, $resourceUrl) { $this->get($data, $resourceUrl); return $this->response; diff --git a/src/Api/Traits/HandlesRequest.php b/src/Api/Traits/HandlesRequest.php index 5cdecaee..4f282652 100644 --- a/src/Api/Traits/HandlesRequest.php +++ b/src/Api/Traits/HandlesRequest.php @@ -24,4 +24,4 @@ abstract protected function post($requestOptions, $resourceUrl); * @return array|bool|Response */ abstract protected function get(array $requestOptions = [], $resourceUrl = ''); -} \ No newline at end of file +} diff --git a/src/Api/Traits/Searchable.php b/src/Api/Traits/Searchable.php index 230841c5..e6c93a9b 100644 --- a/src/Api/Traits/Searchable.php +++ b/src/Api/Traits/Searchable.php @@ -62,7 +62,7 @@ protected function execSearchRequest($query, $scope) */ public function search($query, $limit = Pagination::DEFAULT_LIMIT) { - return $this->paginateCustom(function() use ($query) { + return $this->paginateCustom(function () use ($query) { return $this->execSearchRequest($query, $this->getSearchScope()); })->take($limit); } diff --git a/tests/Bot/ProviderTest.php b/tests/Bot/ProviderTest.php index ed2483bf..f3f7d559 100644 --- a/tests/Bot/ProviderTest.php +++ b/tests/Bot/ProviderTest.php @@ -133,4 +133,4 @@ public function dummyPost() { return $this->post([], ''); } -} \ No newline at end of file +}