From 2dbb1e82bbd39018ec9e5a5c88033183fa523b92 Mon Sep 17 00:00:00 2001 From: Christopher Goddard Date: Thu, 16 Jan 2025 15:45:34 +1100 Subject: [PATCH] Add lint commands + fix lint errors (#554) - Add build + clean commands to makefile - Refine ci gha check - Bump squizlabs/php_codesniffer to 3.11.2 --- .github/workflows/ci.yaml | 7 +- Dockerfile | 3 + Makefile | 8 +- composer.json | 11 ++- composer.lock | 71 +++++++----------- samples/attachments/uploadFileAttachment.php | 2 +- .../attachments/uploadStreamAttachment.php | 2 +- samples/groups/createGroup.php | 1 + samples/groups/getGroups.php | 1 + samples/helpcenter/createArticles.php | 3 +- samples/helpcenter/createSections.php | 2 +- samples/helpcenter/findArticles.php | 2 +- .../helpcenter/findArticlesBySectionId.php | 2 +- samples/helpcenter/findCategories.php | 2 +- samples/helpcenter/findSections.php | 2 +- samples/organizations/createOrganization.php | 1 + samples/sell/getContacts.php | 2 +- .../ticket_fields/createDropdownOption.php | 1 + samples/ticket_fields/editDropdownOption.php | 1 + .../ticket_fields/replaceDropdownOptions.php | 11 +-- samples/tickets/createTicket.php | 2 +- .../tickets/createTicketWithAttachment.php | 4 +- samples/tickets/deleteTicket.php | 2 +- samples/tickets/getTicketComments.php | 2 +- samples/tickets/getTicketMetrics.php | 2 +- samples/tickets/getTickets.php | 2 +- samples/tickets/searchTickets.php | 4 +- samples/tickets/updateTicket.php | 2 +- samples/tickets/viewTicket.php | 2 +- samples/users/createUser.php | 1 + samples/users/getUsers.php | 1 + samples/users/searchUser.php | 1 + .../API/Exceptions/CustomException.php | 1 - .../Exceptions/MissingParametersException.php | 1 - .../API/Exceptions/ResponseException.php | 2 - src/Zendesk/API/HttpClient.php | 8 +- .../API/Resources/Core/AppInstallations.php | 3 +- .../API/Resources/Core/CustomRoles.php | 3 +- .../API/Resources/Core/SharingAgreements.php | 3 +- src/Zendesk/API/Resources/Core/Targets.php | 3 +- .../API/Resources/Core/TicketAudits.php | 1 + .../API/Resources/Core/TicketFields.php | 1 + .../API/Resources/Core/Translations.php | 4 +- src/Zendesk/API/Resources/Core/Triggers.php | 1 + .../API/Resources/Core/TwitterHandles.php | 4 +- .../API/Resources/ResourceAbstract.php | 2 +- src/Zendesk/API/Resources/Talk/Stats.php | 6 +- .../Traits/Resource/CreateOrUpdateMany.php | 1 - src/Zendesk/API/Traits/Resource/Locales.php | 1 - .../API/Traits/Resource/Pagination.php | 9 ++- src/Zendesk/API/Traits/Resource/Update.php | 1 - .../API/Traits/Resource/UpdateMany.php | 1 - .../Utility/Pagination/AbstractStrategy.php | 5 +- .../Traits/Utility/Pagination/CbpStrategy.php | 3 +- .../Traits/Utility/Pagination/ObpStrategy.php | 3 +- .../Utility/Pagination/PaginationError.php | 7 ++ .../Utility/Pagination/PaginationIterator.php | 2 - .../Utility/Pagination/SinglePageStrategy.php | 4 +- src/Zendesk/Console/ConsoleCommand.php | 2 +- .../Console/Matchers/SubResourceMatcher.php | 3 +- src/Zendesk/Fixtures/MockResource.php | 68 +++++++++++++++++ tests/Zendesk/API/LiveTests/BasicTest.php | 8 +- tests/Zendesk/API/LiveTests/UsersTest.php | 1 + tests/Zendesk/API/UnitTests/BasicTest.php | 12 +-- .../Core/AppInstallationLocationsTest.php | 1 - tests/Zendesk/API/UnitTests/Core/AppsTest.php | 1 - .../API/UnitTests/Core/AttachmentsTest.php | 1 - .../API/UnitTests/Core/AutomationsTest.php | 4 +- .../API/UnitTests/Core/DummyResource.php | 2 + .../Zendesk/API/UnitTests/Core/MacrosTest.php | 2 +- .../Core/OrganizationMembershipsTest.php | 2 +- .../API/UnitTests/Core/OrganizationsTest.php | 2 +- .../API/UnitTests/Core/RequestsTest.php | 2 +- .../API/UnitTests/Core/ResourceTest.php | 1 + .../Core/SatisfactionRatingsTest.php | 4 +- .../API/UnitTests/Core/SessionsTest.php | 1 - .../UnitTests/Core/SharingAgreementsTest.php | 1 - tests/Zendesk/API/UnitTests/Core/TagsTest.php | 2 +- .../Core/TicketFieldsOptionsTest.php | 3 +- .../API/UnitTests/Core/TicketFieldsTest.php | 1 - .../API/UnitTests/Core/TicketsTest.php | 2 +- .../API/UnitTests/Core/TranslationsTest.php | 12 +-- .../API/UnitTests/Core/UserIdentitiesTest.php | 1 - .../Exceptions/ApiResponseExceptionTest.php | 4 +- .../API/UnitTests/Sell/ContactsTest.php | 1 - .../Traits/Utility/PaginationIteratorTest.php | 75 ++----------------- 86 files changed, 237 insertions(+), 222 deletions(-) create mode 100644 src/Zendesk/API/Traits/Utility/Pagination/PaginationError.php create mode 100644 src/Zendesk/Fixtures/MockResource.php diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6c1f17c83..86b260085 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,10 @@ jobs: run: docker build . --file Dockerfile --tag zendesk_api_client_php-app - name: Run Composer install - run: docker run --rm --volume "$(pwd):/app" zendesk_api_client_php-app composer install + run: docker run --rm --volume "$(pwd):/app" zendesk_api_client_php-app make build + + - name: Run lint + run: docker run --rm --volume "$(pwd):/app" zendesk_api_client_php-app make lint - name: Run tests - run: docker run --rm --volume "$(pwd):/app" zendesk_api_client_php-app vendor/bin/phpunit --testsuite "Zendesk API Unit Test Suites" + run: docker run --rm --volume "$(pwd):/app" zendesk_api_client_php-app make test diff --git a/Dockerfile b/Dockerfile index 176241647..e5bfc8976 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,9 @@ FROM php:8.2-cli # OS requirements for PHP RUN apt-get update && apt-get install -y git unzip +# Safe requirements to allow Makefile tasks to run +RUN git config --global --add safe.directory /app + # PHP requirements RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer WORKDIR /app diff --git a/Makefile b/Makefile index b92b8b888..32ff52537 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ -.PHONY: test all +.PHONY: build test lint + +build: + composer install test: composer test:unit -all: test +lint: + composer lint diff --git a/composer.json b/composer.json index 435e55a3a..a2a760151 100755 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ }, "require-dev": { "phpunit/phpunit": "11.5.0", - "squizlabs/php_codesniffer": "2.*", + "squizlabs/php_codesniffer": "3.*", "phpmd/phpmd": "@stable", "fakerphp/faker": "^1.24.1", "psy/psysh": "@stable" @@ -19,11 +19,14 @@ "autoload": { "psr-0": { "Zendesk\\API\\": "src/", - "Zendesk\\Console\\": "src/" + "Zendesk\\Console\\": "src/", + "Zendesk\\Fixtures\\": "src/" } - }, +}, "scripts": { "test:unit": "vendor/bin/phpunit --testsuite 'Zendesk API Unit Test Suites'", - "test:live": "vendor/bin/phpunit --testsuite 'Zendesk API Live Test Suites'" + "test:live": "vendor/bin/phpunit --testsuite 'Zendesk API Live Test Suites'", + "lint": "vendor/bin/phpcs --runtime-set ignore_warnings_on_exit 1 --standard=PSR12 --extensions=php --ignore=vendor/ .", + "lint:fix": "vendor/bin/phpcbf --runtime-set ignore_warnings_on_exit 1 --standard=PSR12 --extensions=php --ignore=vendor/ ." } } diff --git a/composer.lock b/composer.lock index 9f162810e..ccb6e7b8d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "64c8bfbf446e10ea66ea6b0d363efbc0", + "content-hash": "98b537b2c22e2f67b8facecd331c30e4", "packages": [ { "name": "guzzlehttp/guzzle", @@ -2779,64 +2779,37 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "2.9.2", + "version": "3.11.2", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "2acf168de78487db620ab4bc524135a13cfe6745" + "reference": "1368f4a58c3c52114b86b1abe8f4098869cb0079" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/2acf168de78487db620ab4bc524135a13cfe6745", - "reference": "2acf168de78487db620ab4bc524135a13cfe6745", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/1368f4a58c3c52114b86b1abe8f4098869cb0079", + "reference": "1368f4a58c3c52114b86b1abe8f4098869cb0079", "shasum": "" }, "require": { "ext-simplexml": "*", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "php": ">=5.1.2" + "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, "bin": [ - "scripts/phpcs", - "scripts/phpcbf" + "bin/phpcbf", + "bin/phpcs" ], "type": "library", "extra": { "branch-alias": { - "dev-master": "2.x-dev" + "dev-master": "3.x-dev" } }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" @@ -2844,19 +2817,29 @@ "authors": [ { "name": "Greg Sherwood", - "role": "lead" + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "http://www.squizlabs.com/php-codesniffer", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", "keywords": [ "phpcs", - "standards" + "standards", + "static analysis" ], "support": { - "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", - "source": "https://github.com/squizlabs/PHP_CodeSniffer", - "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" }, "funding": [ { @@ -2872,7 +2855,7 @@ "type": "open_collective" } ], - "time": "2018-11-07T22:31:41+00:00" + "time": "2024-12-11T16:04:26+00:00" }, { "name": "staabm/side-effects-detector", diff --git a/samples/attachments/uploadFileAttachment.php b/samples/attachments/uploadFileAttachment.php index b96b5e72c..c7571395a 100644 --- a/samples/attachments/uploadFileAttachment.php +++ b/samples/attachments/uploadFileAttachment.php @@ -28,5 +28,5 @@ print_r($attachment); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/attachments/uploadStreamAttachment.php b/samples/attachments/uploadStreamAttachment.php index d0212f5ac..a532de2a5 100644 --- a/samples/attachments/uploadStreamAttachment.php +++ b/samples/attachments/uploadStreamAttachment.php @@ -29,5 +29,5 @@ print_r($attachment); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/groups/createGroup.php b/samples/groups/createGroup.php index 92d61e8eb..d24c37cee 100644 --- a/samples/groups/createGroup.php +++ b/samples/groups/createGroup.php @@ -1,4 +1,5 @@ "; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } - diff --git a/samples/helpcenter/createSections.php b/samples/helpcenter/createSections.php index 4aa13d682..20f14fa23 100644 --- a/samples/helpcenter/createSections.php +++ b/samples/helpcenter/createSections.php @@ -28,5 +28,5 @@ print_r($section); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/helpcenter/findArticles.php b/samples/helpcenter/findArticles.php index 67b1af8da..30bc7592b 100644 --- a/samples/helpcenter/findArticles.php +++ b/samples/helpcenter/findArticles.php @@ -24,5 +24,5 @@ print_r($articles); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/helpcenter/findArticlesBySectionId.php b/samples/helpcenter/findArticlesBySectionId.php index 29dff547c..604534092 100644 --- a/samples/helpcenter/findArticlesBySectionId.php +++ b/samples/helpcenter/findArticlesBySectionId.php @@ -25,5 +25,5 @@ print_r($articles); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/helpcenter/findCategories.php b/samples/helpcenter/findCategories.php index 612595e46..6d766282f 100644 --- a/samples/helpcenter/findCategories.php +++ b/samples/helpcenter/findCategories.php @@ -23,5 +23,5 @@ print_r($categories); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/helpcenter/findSections.php b/samples/helpcenter/findSections.php index 8cec98e6e..bd342728a 100644 --- a/samples/helpcenter/findSections.php +++ b/samples/helpcenter/findSections.php @@ -41,5 +41,5 @@ print_r($sections); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/organizations/createOrganization.php b/samples/organizations/createOrganization.php index 22b0ee167..2ca014820 100644 --- a/samples/organizations/createOrganization.php +++ b/samples/organizations/createOrganization.php @@ -1,4 +1,5 @@ "; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/ticket_fields/createDropdownOption.php b/samples/ticket_fields/createDropdownOption.php index 8d8fc4074..2a0f26a00 100644 --- a/samples/ticket_fields/createDropdownOption.php +++ b/samples/ticket_fields/createDropdownOption.php @@ -1,4 +1,5 @@ setAuth('basic', ['username' => $username, 'token' => $token]); try { - $result = $client->ticketFields()->update(51931448, ["custom_field_options"=> [ + $result = $client->ticketFields()->update(51931448, ["custom_field_options" => [ [ - "name"=> "Apple Pie", - "value"=> "apple_pie" + "name" => "Apple Pie", + "value" => "apple_pie" ], [ - "name"=> "Pecan Pie", - "value"=> "pecan_pie" + "name" => "Pecan Pie", + "value" => "pecan_pie" ] ] ]); diff --git a/samples/tickets/createTicket.php b/samples/tickets/createTicket.php index 0d10e1dcf..219111fc3 100644 --- a/samples/tickets/createTicket.php +++ b/samples/tickets/createTicket.php @@ -36,5 +36,5 @@ print_r($newTicket); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/tickets/createTicketWithAttachment.php b/samples/tickets/createTicketWithAttachment.php index eccacc8f5..01198aadf 100644 --- a/samples/tickets/createTicketWithAttachment.php +++ b/samples/tickets/createTicketWithAttachment.php @@ -11,7 +11,7 @@ $subdomain = "subdomain"; $username = "email@example.com"; $token = "6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv"; -$attachment = getcwd().'/sample.jpg'; +$attachment = getcwd() . '/sample.jpg'; $client = new ZendeskAPI($subdomain); $client->setAuth('basic', ['username' => $username, 'token' => $token]); @@ -46,5 +46,5 @@ print_r($newTicket); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/tickets/deleteTicket.php b/samples/tickets/deleteTicket.php index 15eb75586..6c8f3dc90 100644 --- a/samples/tickets/deleteTicket.php +++ b/samples/tickets/deleteTicket.php @@ -21,5 +21,5 @@ $deleteTicket = $client->tickets()->delete($id); echo "Ticket ($id) has been removed"; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/tickets/getTicketComments.php b/samples/tickets/getTicketComments.php index c44bbc944..9669aa1d1 100644 --- a/samples/tickets/getTicketComments.php +++ b/samples/tickets/getTicketComments.php @@ -25,5 +25,5 @@ print_r($tickets); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/tickets/getTicketMetrics.php b/samples/tickets/getTicketMetrics.php index a94d648bf..740429eff 100644 --- a/samples/tickets/getTicketMetrics.php +++ b/samples/tickets/getTicketMetrics.php @@ -24,5 +24,5 @@ print_r($metrics); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/tickets/getTickets.php b/samples/tickets/getTickets.php index 327caf759..2e697104c 100644 --- a/samples/tickets/getTickets.php +++ b/samples/tickets/getTickets.php @@ -24,5 +24,5 @@ print_r($tickets); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/tickets/searchTickets.php b/samples/tickets/searchTickets.php index 617767736..2a4bbf493 100644 --- a/samples/tickets/searchTickets.php +++ b/samples/tickets/searchTickets.php @@ -17,7 +17,7 @@ try { // Search the current customer - $params = ['query' =>'customer@example.com']; + $params = ['query' => 'customer@example.com']; $search = $client->users()->search($params); if (empty($search->users)) { @@ -34,5 +34,5 @@ } } } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/tickets/updateTicket.php b/samples/tickets/updateTicket.php index 6f76f9e88..854e636a5 100644 --- a/samples/tickets/updateTicket.php +++ b/samples/tickets/updateTicket.php @@ -29,5 +29,5 @@ print_r($updateTicket); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/tickets/viewTicket.php b/samples/tickets/viewTicket.php index 0a8c2cc89..1b56a7398 100644 --- a/samples/tickets/viewTicket.php +++ b/samples/tickets/viewTicket.php @@ -26,5 +26,5 @@ print_r($tickets->ticket); echo ""; } catch (\Zendesk\API\Exceptions\ApiResponseException $e) { - echo $e->getMessage().'
'; + echo $e->getMessage() . '
'; } diff --git a/samples/users/createUser.php b/samples/users/createUser.php index be2e725b4..ef7ee6bcf 100644 --- a/samples/users/createUser.php +++ b/samples/users/createUser.php @@ -1,4 +1,5 @@ subdomain === 'api.futuresimple.com') { $this->apiUrl = 'https://api.futuresimple.com/'; - } else - - if (empty($subdomain)) { + } elseif (empty($subdomain)) { $this->apiUrl = "$scheme://$hostname:$port/"; } else { $this->apiUrl = "$scheme://$subdomain.$hostname:$port/"; diff --git a/src/Zendesk/API/Resources/Core/AppInstallations.php b/src/Zendesk/API/Resources/Core/AppInstallations.php index e6dfaf4ec..16311049c 100644 --- a/src/Zendesk/API/Resources/Core/AppInstallations.php +++ b/src/Zendesk/API/Resources/Core/AppInstallations.php @@ -125,7 +125,8 @@ public function update($id = null, array $updateResourceFields = [], $routeKey = ); } - private function paginationStrategyClass() { + private function paginationStrategyClass() + { return SinglePageStrategy::class; } } diff --git a/src/Zendesk/API/Resources/Core/CustomRoles.php b/src/Zendesk/API/Resources/Core/CustomRoles.php index 5090ba47e..961a25084 100644 --- a/src/Zendesk/API/Resources/Core/CustomRoles.php +++ b/src/Zendesk/API/Resources/Core/CustomRoles.php @@ -14,7 +14,8 @@ class CustomRoles extends ResourceAbstract { use FindAll; - protected function paginationStrategyClass() { + protected function paginationStrategyClass() + { return SinglePageStrategy::class; } } diff --git a/src/Zendesk/API/Resources/Core/SharingAgreements.php b/src/Zendesk/API/Resources/Core/SharingAgreements.php index 709f09e5d..666038cfb 100755 --- a/src/Zendesk/API/Resources/Core/SharingAgreements.php +++ b/src/Zendesk/API/Resources/Core/SharingAgreements.php @@ -14,7 +14,8 @@ class SharingAgreements extends ResourceAbstract { use FindAll; - protected function paginationStrategyClass() { + protected function paginationStrategyClass() + { return SinglePageStrategy::class; } } diff --git a/src/Zendesk/API/Resources/Core/Targets.php b/src/Zendesk/API/Resources/Core/Targets.php index 99ad029f6..7243b1c53 100644 --- a/src/Zendesk/API/Resources/Core/Targets.php +++ b/src/Zendesk/API/Resources/Core/Targets.php @@ -13,7 +13,8 @@ class Targets extends ResourceAbstract { use Defaults; - protected function paginationStrategyClass() { + protected function paginationStrategyClass() + { return SinglePageStrategy::class; } } diff --git a/src/Zendesk/API/Resources/Core/TicketAudits.php b/src/Zendesk/API/Resources/Core/TicketAudits.php index 8d29b6f72..4c2742684 100755 --- a/src/Zendesk/API/Resources/Core/TicketAudits.php +++ b/src/Zendesk/API/Resources/Core/TicketAudits.php @@ -17,6 +17,7 @@ class TicketAudits extends ResourceAbstract findAll as traitFindAll; find as traitFind; } + /** * {@inheritdoc} */ diff --git a/src/Zendesk/API/Resources/Core/TicketFields.php b/src/Zendesk/API/Resources/Core/TicketFields.php index 8e1149718..6eb990bca 100755 --- a/src/Zendesk/API/Resources/Core/TicketFields.php +++ b/src/Zendesk/API/Resources/Core/TicketFields.php @@ -1,4 +1,5 @@ findAll($params, __FUNCTION__); } - -} \ No newline at end of file +} diff --git a/src/Zendesk/API/Resources/Core/Triggers.php b/src/Zendesk/API/Resources/Core/Triggers.php index 516c9479e..891ddca1d 100755 --- a/src/Zendesk/API/Resources/Core/Triggers.php +++ b/src/Zendesk/API/Resources/Core/Triggers.php @@ -1,4 +1,5 @@ apiBasePath = $apiBasePath; $this->client = $client; diff --git a/src/Zendesk/API/Resources/Talk/Stats.php b/src/Zendesk/API/Resources/Talk/Stats.php index 7af3c27b3..f0293ebe0 100644 --- a/src/Zendesk/API/Resources/Talk/Stats.php +++ b/src/Zendesk/API/Resources/Talk/Stats.php @@ -41,7 +41,7 @@ public function currentQueue() return $this->client->get($route); } - + /** * Account overview. * @@ -56,7 +56,7 @@ public function accountOverview() return $this->client->get($route); } - + /** * Agents overview. * @@ -71,7 +71,7 @@ public function agentsOverview() return $this->client->get($route); } - + /** * Agents activity. * diff --git a/src/Zendesk/API/Traits/Resource/CreateOrUpdateMany.php b/src/Zendesk/API/Traits/Resource/CreateOrUpdateMany.php index a68422da8..5d97aa3e9 100644 --- a/src/Zendesk/API/Traits/Resource/CreateOrUpdateMany.php +++ b/src/Zendesk/API/Traits/Resource/CreateOrUpdateMany.php @@ -9,7 +9,6 @@ */ trait CreateOrUpdateMany { - /** * Update group of resources * diff --git a/src/Zendesk/API/Traits/Resource/Locales.php b/src/Zendesk/API/Traits/Resource/Locales.php index 552f403da..00094a8a5 100644 --- a/src/Zendesk/API/Traits/Resource/Locales.php +++ b/src/Zendesk/API/Traits/Resource/Locales.php @@ -7,7 +7,6 @@ */ trait Locales { - /** * Used for setting up the locale * @var locale diff --git a/src/Zendesk/API/Traits/Resource/Pagination.php b/src/Zendesk/API/Traits/Resource/Pagination.php index 2d80ac709..ee1a3677d 100644 --- a/src/Zendesk/API/Traits/Resource/Pagination.php +++ b/src/Zendesk/API/Traits/Resource/Pagination.php @@ -5,7 +5,8 @@ use Zendesk\API\Traits\Utility\Pagination\CbpStrategy; use Zendesk\API\Traits\Utility\Pagination\PaginationIterator; -trait Pagination { +trait Pagination +{ /** * Usage: * $ticketsIterator = $client->tickets()->iterator(); @@ -28,7 +29,8 @@ public function iterator($params = [], $method = 'findAll') * * @return string subclass of AbstractStrategy used for fetching pages */ - protected function paginationStrategyClass() { + protected function paginationStrategyClass() + { return CbpStrategy::class; } @@ -37,7 +39,8 @@ protected function paginationStrategyClass() { * * @return string eg: "job_statuses" */ - protected function resourcesKey() { + protected function resourcesKey() + { return $this->objectNamePlural; } } diff --git a/src/Zendesk/API/Traits/Resource/Update.php b/src/Zendesk/API/Traits/Resource/Update.php index 1289adc23..76517c2ac 100644 --- a/src/Zendesk/API/Traits/Resource/Update.php +++ b/src/Zendesk/API/Traits/Resource/Update.php @@ -6,7 +6,6 @@ trait Update { - /** * Update a resource * diff --git a/src/Zendesk/API/Traits/Resource/UpdateMany.php b/src/Zendesk/API/Traits/Resource/UpdateMany.php index 96af36924..fb48a51c3 100644 --- a/src/Zendesk/API/Traits/Resource/UpdateMany.php +++ b/src/Zendesk/API/Traits/Resource/UpdateMany.php @@ -10,7 +10,6 @@ */ trait UpdateMany { - /** * Update group of resources * diff --git a/src/Zendesk/API/Traits/Utility/Pagination/AbstractStrategy.php b/src/Zendesk/API/Traits/Utility/Pagination/AbstractStrategy.php index 5838505c0..17c5d3933 100644 --- a/src/Zendesk/API/Traits/Utility/Pagination/AbstractStrategy.php +++ b/src/Zendesk/API/Traits/Utility/Pagination/AbstractStrategy.php @@ -1,4 +1,5 @@ pageSize)) { return $this->pageSize; - } else if (isset($this->params['page[size]'])) { + } elseif (isset($this->params['page[size]'])) { $this->pageSize = $this->params['page[size]']; - } else if (isset($this->params['per_page'])) { + } elseif (isset($this->params['per_page'])) { $this->pageSize = $this->params['per_page']; } else { $this->pageSize = DEFAULT_PAGE_SIZE; diff --git a/src/Zendesk/API/Traits/Utility/Pagination/CbpStrategy.php b/src/Zendesk/API/Traits/Utility/Pagination/CbpStrategy.php index 6a7874fe2..6c84b95d8 100644 --- a/src/Zendesk/API/Traits/Utility/Pagination/CbpStrategy.php +++ b/src/Zendesk/API/Traits/Utility/Pagination/CbpStrategy.php @@ -29,7 +29,8 @@ public function page($getPageFn) return $this->latestResponse->{$this->resourcesKey}; } - public function shouldGetPage($current_page) { + public function shouldGetPage($current_page) + { return !$this->started || $this->hasMore; } diff --git a/src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php b/src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php index 966355b21..03fe2ddee 100644 --- a/src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php +++ b/src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php @@ -18,7 +18,8 @@ public function page($getPageFn) return $response->{$this->resourcesKey}; } - public function shouldGetPage($current_page) { + public function shouldGetPage($current_page) + { return $this->pageNumber == 0 || count($current_page) == 0; } } diff --git a/src/Zendesk/API/Traits/Utility/Pagination/PaginationError.php b/src/Zendesk/API/Traits/Utility/Pagination/PaginationError.php new file mode 100644 index 000000000..d2873a397 --- /dev/null +++ b/src/Zendesk/API/Traits/Utility/Pagination/PaginationError.php @@ -0,0 +1,7 @@ +{$this->resourcesKey}; } - public function shouldGetPage($current_page) { + public function shouldGetPage($current_page) + { return !$this->started; } } diff --git a/src/Zendesk/Console/ConsoleCommand.php b/src/Zendesk/Console/ConsoleCommand.php index 80eb17b9e..8f8a38d07 100644 --- a/src/Zendesk/Console/ConsoleCommand.php +++ b/src/Zendesk/Console/ConsoleCommand.php @@ -40,7 +40,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $config = new Configuration; + $config = new Configuration(); $client = new HttpClient($input->getArgument('subdomain')); $client->setAuth('basic', [ diff --git a/src/Zendesk/Console/Matchers/SubResourceMatcher.php b/src/Zendesk/Console/Matchers/SubResourceMatcher.php index 8b56fc692..f697d3dda 100644 --- a/src/Zendesk/Console/Matchers/SubResourceMatcher.php +++ b/src/Zendesk/Console/Matchers/SubResourceMatcher.php @@ -8,7 +8,6 @@ class SubResourceMatcher extends AbstractContextAwareMatcher { - /** * Provide tab completion matches for readline input. * @@ -91,7 +90,7 @@ private function methodAttributeMatcher($object, $input = '') private function methodMatcher($object, $input = '') { $subresources = method_exists($object, 'getValidSubResources') ? - array_keys($object->getValidSubResources()): []; + array_keys($object->getValidSubResources()) : []; $methods = array_reduce( array_merge($subresources, get_class_methods($object)), diff --git a/src/Zendesk/Fixtures/MockResource.php b/src/Zendesk/Fixtures/MockResource.php new file mode 100644 index 000000000..51dbcc875 --- /dev/null +++ b/src/Zendesk/Fixtures/MockResource.php @@ -0,0 +1,68 @@ +resourceName = $resourceName; + $this->resources = $resources; + $this->callCount = 0; + } + + public function findAll($params) + { + if ($this->errorMessage) { + $request = new Request('GET', 'http://example.zendesk.com'); + $this->response = new Response(400, [], '{ "a": "json"}'); + $requestException = new RequestException($this->errorMessage, $request, $this->response); + throw new ApiResponseException($requestException); + } elseif ($this->isObp) { + $this->response = (object) [ + $this->resourceName => $this->resources[0], + // No CBP meta and links + ]; + } else { + // Simulate two pages of resources + $resources = $this->callCount === 0 + ? $this->resources[0] + : $this->resources[1]; + + // Simulate a cursor for the next page on the first call + $afterCursor = $this->callCount === 0 ? 'cursor_for_next_page' : null; + + $this->callCount++; + $this->params = $params; + $this->response = (object) [ + $this->resourceName => $resources, + 'meta' => (object) [ + 'has_more' => $afterCursor !== null, + 'after_cursor' => $afterCursor, + ], + ]; + } + + return $this->response; + } + + public function findDifferent($params) + { + $this->foundDifferent = true; + return $this->findAll($params); + } +} diff --git a/tests/Zendesk/API/LiveTests/BasicTest.php b/tests/Zendesk/API/LiveTests/BasicTest.php index 98efb1c6d..7779de70b 100644 --- a/tests/Zendesk/API/LiveTests/BasicTest.php +++ b/tests/Zendesk/API/LiveTests/BasicTest.php @@ -1,12 +1,12 @@ assertSame( - 0, strpos($request->getUri()->getPath(), $options['apiBasePath']), + 0, + strpos($request->getUri()->getPath(), $options['apiBasePath']), "Failed asserting apiBasePath: expected: {$options['apiBasePath']}, actual: {$request->getUri()->getPath()}" ); } @@ -196,8 +196,10 @@ public function assertRequestIs($options, $index = 0) // $options['endpoint'] does not include the api/v2 base path $endpoint = preg_replace('/^' . preg_quote($options['apiBasePath'], '/') . '/', '', $request->getUri()->getPath()); $this->assertEquals( - $options['endpoint'], $endpoint, - "Failed asserting endpoint: expected: {$options['endpoint']}, actual: {$endpoint}"); + $options['endpoint'], + $endpoint, + "Failed asserting endpoint: expected: {$options['endpoint']}, actual: {$endpoint}" + ); } if (isset($options['queryParams'])) { @@ -244,7 +246,7 @@ protected function assertEndpointCalled($userFunction, $endpoint, $method = 'GET * @param \Iterator $iterator * @return array all the items */ - protected function iterator_to_array($iterator) + protected function iteratorToArray($iterator) { $results = []; foreach ($iterator as $item) { diff --git a/tests/Zendesk/API/UnitTests/Core/AppInstallationLocationsTest.php b/tests/Zendesk/API/UnitTests/Core/AppInstallationLocationsTest.php index a1320e485..05e45f90b 100644 --- a/tests/Zendesk/API/UnitTests/Core/AppInstallationLocationsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/AppInstallationLocationsTest.php @@ -9,7 +9,6 @@ */ class AppInstallationLocationsTest extends BasicTest { - /** * Test get incremental export for tickets */ diff --git a/tests/Zendesk/API/UnitTests/Core/AppsTest.php b/tests/Zendesk/API/UnitTests/Core/AppsTest.php index 3001b9bcc..1796750ff 100644 --- a/tests/Zendesk/API/UnitTests/Core/AppsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/AppsTest.php @@ -10,7 +10,6 @@ */ class AppsTest extends BasicTest { - /** * Test uploading of App */ diff --git a/tests/Zendesk/API/UnitTests/Core/AttachmentsTest.php b/tests/Zendesk/API/UnitTests/Core/AttachmentsTest.php index 0cfec163e..508e20fc1 100755 --- a/tests/Zendesk/API/UnitTests/Core/AttachmentsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/AttachmentsTest.php @@ -10,7 +10,6 @@ */ class AttachmentsTest extends BasicTest { - /** * Test upload of file */ diff --git a/tests/Zendesk/API/UnitTests/Core/AutomationsTest.php b/tests/Zendesk/API/UnitTests/Core/AutomationsTest.php index b600e65ae..7f073c0f8 100755 --- a/tests/Zendesk/API/UnitTests/Core/AutomationsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/AutomationsTest.php @@ -40,7 +40,7 @@ public function testIterator() $iterator = $this->client->automations()->iterator(); - $actual = $this->iterator_to_array($iterator); + $actual = $this->iteratorToArray($iterator); $this->assertCount(3, $actual); $this->assertEquals($this->testResource0['anyField'], $actual[0]->anyField); $this->assertEquals($this->testResource1['anyField'], $actual[1]->anyField); @@ -65,7 +65,7 @@ public function testIteratorFindActive() $iterator = $this->client->automations()->iterator([], 'findActive'); - $actual = $this->iterator_to_array($iterator); + $actual = $this->iteratorToArray($iterator); $this->assertLastRequestIs( [ diff --git a/tests/Zendesk/API/UnitTests/Core/DummyResource.php b/tests/Zendesk/API/UnitTests/Core/DummyResource.php index f4b2bac74..fb4a5c24b 100644 --- a/tests/Zendesk/API/UnitTests/Core/DummyResource.php +++ b/tests/Zendesk/API/UnitTests/Core/DummyResource.php @@ -1,4 +1,5 @@ client->macros()->iterator(); - $actual = $this->iterator_to_array($iterator); + $actual = $this->iteratorToArray($iterator); $this->assertCount(3, $actual); $this->assertEquals($this->testResource0['anyField'], $actual[0]->anyField); $this->assertEquals($this->testResource1['anyField'], $actual[1]->anyField); diff --git a/tests/Zendesk/API/UnitTests/Core/OrganizationMembershipsTest.php b/tests/Zendesk/API/UnitTests/Core/OrganizationMembershipsTest.php index 8de9e2cef..0a0c7411f 100644 --- a/tests/Zendesk/API/UnitTests/Core/OrganizationMembershipsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/OrganizationMembershipsTest.php @@ -40,7 +40,7 @@ public function testIterator() $iterator = $this->client->organizationMemberships()->iterator(); - $actual = $this->iterator_to_array($iterator); + $actual = $this->iteratorToArray($iterator); $this->assertCount(3, $actual); $this->assertEquals($this->testResource0['anyField'], $actual[0]->anyField); $this->assertEquals($this->testResource1['anyField'], $actual[1]->anyField); diff --git a/tests/Zendesk/API/UnitTests/Core/OrganizationsTest.php b/tests/Zendesk/API/UnitTests/Core/OrganizationsTest.php index e8f6e1c1c..a9022bdcd 100644 --- a/tests/Zendesk/API/UnitTests/Core/OrganizationsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/OrganizationsTest.php @@ -40,7 +40,7 @@ public function testIterator() $iterator = $this->client->organizations()->iterator(); - $actual = $this->iterator_to_array($iterator); + $actual = $this->iteratorToArray($iterator); $this->assertCount(3, $actual); $this->assertEquals($this->testResource0['anyField'], $actual[0]->anyField); $this->assertEquals($this->testResource1['anyField'], $actual[1]->anyField); diff --git a/tests/Zendesk/API/UnitTests/Core/RequestsTest.php b/tests/Zendesk/API/UnitTests/Core/RequestsTest.php index d72b91ce5..e41aeae8d 100755 --- a/tests/Zendesk/API/UnitTests/Core/RequestsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/RequestsTest.php @@ -40,7 +40,7 @@ public function testIterator() $iterator = $this->client->requests()->iterator(); - $actual = $this->iterator_to_array($iterator); + $actual = $this->iteratorToArray($iterator); $this->assertCount(3, $actual); $this->assertEquals($this->testResource0['anyField'], $actual[0]->anyField); $this->assertEquals($this->testResource1['anyField'], $actual[1]->anyField); diff --git a/tests/Zendesk/API/UnitTests/Core/ResourceTest.php b/tests/Zendesk/API/UnitTests/Core/ResourceTest.php index 03ea212b2..c5a1ffb23 100644 --- a/tests/Zendesk/API/UnitTests/Core/ResourceTest.php +++ b/tests/Zendesk/API/UnitTests/Core/ResourceTest.php @@ -1,4 +1,5 @@ client->satisfactionRatings()->iterator(); - $actual = $this->iterator_to_array($iterator); + $actual = $this->iteratorToArray($iterator); $this->assertCount(3, $actual); $this->assertEquals($this->testResource0['anyField'], $actual[0]->anyField); $this->assertEquals($this->testResource1['anyField'], $actual[1]->anyField); @@ -89,7 +89,7 @@ public function testCreateNeedsTicketId() ]; $this->expectException(\Zendesk\API\Exceptions\MissingParametersException::class); - $this->expectExceptionMessage("Missing parameters: 'ticket_id' must be supplied for Zendesk\API\Resources\Core\SatisfactionRatings::create"); + $this->expectExceptionMessage("Missing parameters: 'ticket_id' must be supplied for Zendesk\API\Resources\Core\SatisfactionRatings::create"); $this->client->satisfactionRatings()->create($postParams); } diff --git a/tests/Zendesk/API/UnitTests/Core/SessionsTest.php b/tests/Zendesk/API/UnitTests/Core/SessionsTest.php index 27c8f7918..8864544fe 100644 --- a/tests/Zendesk/API/UnitTests/Core/SessionsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/SessionsTest.php @@ -6,7 +6,6 @@ class SessionsTest extends BasicTest { - /** * Tests if the delete user session is accessible if the ID is passed */ diff --git a/tests/Zendesk/API/UnitTests/Core/SharingAgreementsTest.php b/tests/Zendesk/API/UnitTests/Core/SharingAgreementsTest.php index 124c64a14..6964e1f3c 100755 --- a/tests/Zendesk/API/UnitTests/Core/SharingAgreementsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/SharingAgreementsTest.php @@ -9,7 +9,6 @@ */ class SharingAgreementsTest extends BasicTest { - /** * Test that the findAll method was included */ diff --git a/tests/Zendesk/API/UnitTests/Core/TagsTest.php b/tests/Zendesk/API/UnitTests/Core/TagsTest.php index 21371da64..8c4eb3188 100644 --- a/tests/Zendesk/API/UnitTests/Core/TagsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/TagsTest.php @@ -39,7 +39,7 @@ public function testIterator() ]); $iterator = $this->client->tags()->iterator(); - $actual = $this->iterator_to_array($iterator); + $actual = $this->iteratorToArray($iterator); $this->assertCount(3, $actual); $this->assertEquals($this->testResource0['anyField'], $actual[0]->anyField); diff --git a/tests/Zendesk/API/UnitTests/Core/TicketFieldsOptionsTest.php b/tests/Zendesk/API/UnitTests/Core/TicketFieldsOptionsTest.php index 7bfc6e996..a2d85a897 100644 --- a/tests/Zendesk/API/UnitTests/Core/TicketFieldsOptionsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/TicketFieldsOptionsTest.php @@ -10,7 +10,6 @@ */ class TicketFieldsOptionsTest extends BasicTest { - /** * Tests if the unique routes are called correctly */ @@ -20,7 +19,7 @@ public function testRoutes() $id = 123; $optionValues = [ 'name' => 'one more', - 'value'=> 'ça bouge', + 'value' => 'ça bouge', ]; // FindAll diff --git a/tests/Zendesk/API/UnitTests/Core/TicketFieldsTest.php b/tests/Zendesk/API/UnitTests/Core/TicketFieldsTest.php index b6355fe30..56ff9e2d7 100755 --- a/tests/Zendesk/API/UnitTests/Core/TicketFieldsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/TicketFieldsTest.php @@ -10,7 +10,6 @@ */ class TicketFieldsTest extends BasicTest { - /** * Test that the resource name was set correctly */ diff --git a/tests/Zendesk/API/UnitTests/Core/TicketsTest.php b/tests/Zendesk/API/UnitTests/Core/TicketsTest.php index 8df86ace1..f615a829a 100755 --- a/tests/Zendesk/API/UnitTests/Core/TicketsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/TicketsTest.php @@ -53,7 +53,7 @@ public function testIteratorToArray() $iterator = $this->client->tickets()->iterator(); - $actual = $this->iterator_to_array($iterator); + $actual = $this->iteratorToArray($iterator); $this->assertCount(2, $actual); $this->assertEquals($this->testTicket['subject'], $actual[0]->subject); $this->assertEquals($this->testTicket2['subject'], $actual[1]->subject); diff --git a/tests/Zendesk/API/UnitTests/Core/TranslationsTest.php b/tests/Zendesk/API/UnitTests/Core/TranslationsTest.php index c842d230b..3a81b3183 100644 --- a/tests/Zendesk/API/UnitTests/Core/TranslationsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/TranslationsTest.php @@ -12,10 +12,10 @@ class TranslationsTest extends BasicTest /** * Test manifest method */ -public function testFindManifest() -{ - $this->assertEndpointCalled(function () { - $this->client->translations()->manifest(); - }, 'translations/manifest.json'); -} + public function testFindManifest() + { + $this->assertEndpointCalled(function () { + $this->client->translations()->manifest(); + }, 'translations/manifest.json'); + } } diff --git a/tests/Zendesk/API/UnitTests/Core/UserIdentitiesTest.php b/tests/Zendesk/API/UnitTests/Core/UserIdentitiesTest.php index 518a9adb3..dc16871fb 100755 --- a/tests/Zendesk/API/UnitTests/Core/UserIdentitiesTest.php +++ b/tests/Zendesk/API/UnitTests/Core/UserIdentitiesTest.php @@ -10,7 +10,6 @@ */ class UserIdentitiesTest extends BasicTest { - /** * Tests if the unique routes are called correctly */ diff --git a/tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php b/tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php index c636139b8..e9e151fe5 100644 --- a/tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php +++ b/tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php @@ -13,8 +13,8 @@ class ApiResponseExceptionTest extends BasicTest { public function testServerException() { - $request = new Request("GET",""); - $response = new Response(200, ["Content-Type"=> "application/json"],""); + $request = new Request("GET", ""); + $response = new Response(200, ["Content-Type" => "application/json"], ""); $requestException = new ServerException("test", $request, $response); $subject = new ApiResponseException($requestException); diff --git a/tests/Zendesk/API/UnitTests/Sell/ContactsTest.php b/tests/Zendesk/API/UnitTests/Sell/ContactsTest.php index cbef554e3..4d1405713 100644 --- a/tests/Zendesk/API/UnitTests/Sell/ContactsTest.php +++ b/tests/Zendesk/API/UnitTests/Sell/ContactsTest.php @@ -7,7 +7,6 @@ class ContactsTest extends BasicTest { - /** * Test that the correct traits were added by checking the available methods */ diff --git a/tests/Zendesk/API/UnitTests/Traits/Utility/PaginationIteratorTest.php b/tests/Zendesk/API/UnitTests/Traits/Utility/PaginationIteratorTest.php index c6c5a52c9..d1ec6902d 100644 --- a/tests/Zendesk/API/UnitTests/Traits/Utility/PaginationIteratorTest.php +++ b/tests/Zendesk/API/UnitTests/Traits/Utility/PaginationIteratorTest.php @@ -2,74 +2,13 @@ namespace Zendesk\API\UnitTests\Core; -use GuzzleHttp\Exception\RequestException; -use GuzzleHttp\Psr7\Request; -use GuzzleHttp\Psr7\Response; use Zendesk\API\Exceptions\ApiResponseException; use Zendesk\API\Traits\Utility\Pagination\CbpStrategy; -use Zendesk\API\Traits\Utility\Pagination\PaginationError; use Zendesk\API\Traits\Utility\Pagination\SinglePageStrategy; use Zendesk\API\UnitTests\BasicTest; +use Zendesk\API\Traits\Utility\Pagination\PaginationError; use Zendesk\API\Traits\Utility\Pagination\PaginationIterator; - -class MockResource { - public $params; - public $foundDifferent = false; - public $isObp = false; - public $errorMessage; - public $response; - private $resources; - private $resourceName; - private $callCount = 0; - - public function __construct($resourceName, $resources) - { - $this->resourceName = $resourceName; - $this->resources = $resources; - $this->callCount = 0; - } - - public function findAll($params) - { - if ($this->errorMessage) { - $request = new Request('GET', 'http://example.zendesk.com'); - $this->response = new Response(400, [], '{ "a": "json"}'); - $requestException = new RequestException($this->errorMessage, $request, $this->response); - throw new ApiResponseException($requestException); - } else if ($this->isObp) { - $this->response = (object) [ - $this->resourceName => $this->resources[0], - // No CBP meta and links - ]; - } else { - // Simulate two pages of resources - $resources = $this->callCount === 0 - ? $this->resources[0] - : $this->resources[1]; - - // Simulate a cursor for the next page on the first call - $afterCursor = $this->callCount === 0 ? 'cursor_for_next_page' : null; - - $this->callCount++; - $this->params = $params; - $this->response = (object) [ - $this->resourceName => $resources, - 'meta' => (object) [ - 'has_more' => $afterCursor !== null, - 'after_cursor' => $afterCursor, - ], - ]; - } - - return $this->response; - } - - public function findDifferent($params) - { - $this->foundDifferent = true; - return $this->findAll($params); - } -} +use Zendesk\Fixtures\MockResource; class PaginationIteratorTest extends BasicTest { @@ -82,7 +21,7 @@ public function testFetchesTickets() $strategy = new CbpStrategy('tickets', ['page[size]' => 2]); $iterator = new PaginationIterator($mockTickets, $strategy, 'findAll'); - $tickets = $this->iterator_to_array($iterator); + $tickets = $this->iteratorToArray($iterator); $this->assertEquals([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4]], $tickets); $this->assertEquals($mockTickets->response, $iterator->latestResponse()); @@ -113,7 +52,7 @@ public function testFetchesUsers() $strategy = new CbpStrategy('users', ['page[size]' => 2]); $iterator = new PaginationIterator($mockUsers, $strategy, 'findAll'); - $users = $this->iterator_to_array($iterator); + $users = $this->iteratorToArray($iterator); $this->assertEquals([ ['id' => 1, 'name' => 'User 1'], @@ -132,7 +71,7 @@ public function testFetchesCbpWithParams() $strategy = new CbpStrategy('tickets', ['page[size]' => 2, 'any' => 'param']); $iterator = new PaginationIterator($mockTickets, $strategy, 'findAll'); - $tickets = $this->iterator_to_array($iterator); + $tickets = $this->iteratorToArray($iterator); $this->assertEquals([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4]], $tickets); $this->assertEquals([ @@ -151,7 +90,7 @@ public function testFetchesSinglePageWithParams() $strategy = new SinglePageStrategy($resultsKey, $userParams); $iterator = new PaginationIterator($mockResults, $strategy, 'findAll'); - $resources = $this->iterator_to_array($iterator); + $resources = $this->iteratorToArray($iterator); $this->assertEquals([ ['id' => 1, 'name' => 'Resource 1'], @@ -169,7 +108,7 @@ public function testCustomMethod() $strategy = new SinglePageStrategy($resultsKey, $userParams); $iterator = new PaginationIterator($mockResults, $strategy, 'findDifferent'); - $resources = $this->iterator_to_array($iterator); + $resources = $this->iteratorToArray($iterator); $this->assertEquals([ ['id' => 1, 'name' => 'Resource 1'],