diff --git a/docker-compose.yml b/docker-compose.yml index 36189baa..f3c72060 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,11 +7,11 @@ services: volumes: - .:/app - vendor:/app/vendor - command: vendor/bin/phpunit --testsuite "Zendesk API Unit Test Suites" + # command: vendor/bin/phpunit --testsuite "Zendesk API Unit Test Suites" # command: vendor/bin/phpunit --testdox --testsuite "Zendesk API Unit Test Suites" # command: vendor/bin/phpunit tests/Zendesk/API/UnitTests/Traits/Utility/PaginationIteratorTest.php # command: vendor/bin/phpunit tests/Zendesk/API/UnitTests/Core/TicketsTest.php - # command: vendor/bin/phpunit tests/Zendesk/API/UnitTests/Core/TagsTest.php + command: vendor/bin/phpunit tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php volumes: vendor: diff --git a/src/Zendesk/API/Traits/Utility/Pagination/CbpStrategy.php b/src/Zendesk/API/Traits/Utility/Pagination/CbpStrategy.php index 49d38164..796fde6f 100644 --- a/src/Zendesk/API/Traits/Utility/Pagination/CbpStrategy.php +++ b/src/Zendesk/API/Traits/Utility/Pagination/CbpStrategy.php @@ -43,7 +43,7 @@ public function params() * OBP: https://{subdomain}.zendesk.com/api/v2/tickets?sort_order=desc&sort_by=updated_at&per_page=2 * CBP: https://{subdomain}.zendesk.com/api/v2/tickets?sort=-updated_at&page[size]=2 * - * @return array all params with CBP sorting order + * @return array Params with proper CBP sorting order */ private function sortParams() { @@ -58,7 +58,7 @@ private function sortParams() * The params that are needed to for pagination (eg: ["page[size]" => "100"]) * If OBP params are passed, they are converted to CBP * - * @return array all params with CBP sorting order + * @return array Params for pagination */ private function paginationParams() { diff --git a/src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php b/src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php index 52c3b20c..c32b4cd5 100644 --- a/src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php +++ b/src/Zendesk/API/Traits/Utility/Pagination/ObpStrategy.php @@ -21,9 +21,4 @@ public function page($getPageFn) public function shouldGetPage($position) { return $this->pageNumber == 0 || $position >= $this->pageNumber * $this->pageSize(); } - public function paramsWithPagination() - { - return ['page' => $this->pageNumber, 'per_page' => $this->pageSize()]; - - } } diff --git a/src/Zendesk/API/Traits/Utility/Pagination/PaginationIterator.php b/src/Zendesk/API/Traits/Utility/Pagination/PaginationIterator.php index bb6f664e..3565749d 100644 --- a/src/Zendesk/API/Traits/Utility/Pagination/PaginationIterator.php +++ b/src/Zendesk/API/Traits/Utility/Pagination/PaginationIterator.php @@ -15,7 +15,6 @@ class PaginationIterator implements Iterator private $items = []; /** - * * @param mixed using trait FindAll. The resources collection, Eg: `$client->tickets()` which uses FindAll * @param AbstractStrategy $strategy For pagination Logic (OBP, CBP, SinglePage) * @param string $method used to make the API call diff --git a/tests/Zendesk/API/UnitTests/Core/AuthTest.php b/tests/Zendesk/API/UnitTests/Core/AuthTest.php index de8c1c08..cd7a9910 100755 --- a/tests/Zendesk/API/UnitTests/Core/AuthTest.php +++ b/tests/Zendesk/API/UnitTests/Core/AuthTest.php @@ -2,11 +2,7 @@ namespace Zendesk\API\UnitTests\Core; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; -use GuzzleHttp\Psr7\Response; -use Zendesk\API\Http; -use Zendesk\API\HttpClient; use Zendesk\API\UnitTests\BasicTest; use Zendesk\API\Utilities\Auth; @@ -15,35 +11,6 @@ */ class AuthTest extends BasicTest { - /** - * Test if request is still sent even without authentication - */ - public function testAnonymousAccess() - { - $this->markTestSkipped('Broken in PHP 7.4 (mocking)'); - - // mock client - $client = $this - ->getMockBuilder(HttpClient::class) - ->disableOriginalConstructor() - ->getMock(); - $client->method('getHeaders')->willReturn([]); - $client->expects(self::once())->method('getAuth')->willReturn(null); - - // prepareRequest should not be called - $auth = $this - ->getMockBuilder(Auth::class) - ->disableOriginalConstructor() - ->getMock(); - $auth->expects(self::never())->method('prepareRequest'); - $client->expects(self::once())->method('getAuth')->willReturn($auth); - - // send request - $client->guzzle = $this->getMockBuilder(Client::class)->getMock(); - $client->guzzle->method('send')->willReturn(new Response(200, [], '')); - Http::send($client, ''); - } - /** * Test the preparing of a request for basic authentication. */ diff --git a/tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php b/tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php index 073c7995..c636139b 100644 --- a/tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php +++ b/tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php @@ -2,27 +2,23 @@ namespace Zendesk\API\UnitTests\Exceptions; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Exception\ServerException; +use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Psr7\Response; use Zendesk\API\UnitTests\BasicTest; use Zendesk\API\Exceptions\ApiResponseException; class ApiResponseExceptionTest extends BasicTest { - /** - * Tests if previous exception was passed to ApiResponseException - */ - public function testPreviousException() + public function testServerException() { - $this->markTestSkipped('Broken in PHP 7.4 (mocking)'); + $request = new Request("GET",""); + $response = new Response(200, ["Content-Type"=> "application/json"],""); + $requestException = new ServerException("test", $request, $response); - $message = 'The previous exception was not passed to ApiResponseException'; - $mockException = $this - ->getMockBuilder('GuzzleHttp\Exception\RequestException') - ->disableOriginalConstructor() - ->getMock(); - $mockException->method('hasResponse')->willReturn(true); - $apiException = new ApiResponseException($mockException); - $previousException = $apiException->getPrevious(); + $subject = new ApiResponseException($requestException); - $this->assertEquals($mockException, $previousException, $message); + $this->assertEquals([], $subject->getErrorDetails()); } } diff --git a/tests/Zendesk/API/UnitTests/HttpTest.php b/tests/Zendesk/API/UnitTests/HttpTest.php index bfad1461..65a854c1 100644 --- a/tests/Zendesk/API/UnitTests/HttpTest.php +++ b/tests/Zendesk/API/UnitTests/HttpTest.php @@ -2,63 +2,13 @@ namespace Zendesk\API\UnitTests; -use Exception; -use Faker\Factory; -use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Stream; -use Zendesk\API\Http; -use Zendesk\API\HttpClient; class HttpTest extends BasicTest { - /** - * Test that original request exception is preserved. - */ - public function testOriginalRequestExceptionIsPreserved() - { - $this->markTestSkipped('Broken in PHP 7.4 (mocking)'); - $faker = Factory::create(); - - $exceptionMessage = $faker->sentence; - $exception = $this->mockRequestException($exceptionMessage); - - $guzzleClient = $this->getMockBuilder(GuzzleClient::class) - ->disableOriginalConstructor() - ->getMock(); - $guzzleClient->expects($this->once()) - ->method('send') - ->will($this->throwException($exception)); - - $zendeskClient = $this->getMockBuilder(HttpClient::class) - ->setConstructorArgs([ - $faker->domainWord, - $faker->userName, - $faker->randomElement([ - 'https', - 'http', - ]), - $faker->domainName, - $faker->numberBetween(1), - $guzzleClient, - ]) - ->getMock(); - - $zendeskClient->expects($this->once()) - ->method('getHeaders') - ->will($this->returnValue([])); - - try { - Http::send($zendeskClient, '/'); - } catch (Exception $e) { - $originalException = $e->getPrevious()->getPrevious(); - $this->assertNotNull($originalException); - $this->assertEquals($originalException->getMessage(), $exceptionMessage); - } - } - /** * Create a mocked RequestExcpetion *