diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e78f4edb1..811ba71fb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,18 +10,22 @@ ### Test suite -```sh -# TODO: Update CONTRIBUTING -docker-compose up -docker run -it --rm -v $(pwd):/app zendesk_api_client_php-app bash -``` - The test suite is run via phpunit. Note that these are all live tests that must be run targeted at a real Zendesk instance. Credentials can be provided by setting the environment variables in phpunit.xml; a sample is provided at phpunit.xml.dist. To run the unit tests: `vendor/bin/phpunit --testsuite "Zendesk API Unit Test Suites"` To run the live tests: `vendor/bin/phpunit --testsuite "Zendesk API Live Test Suites"` +### Docker + +If you prefer to use Docker for running your tests: + +```sh +# Run the specs +docker-compose up +# Or open a shell in the container +docker run -it --rm -v $(pwd):/app zendesk_api_client_php-app bash +``` ## Coding Standard diff --git a/README.md b/README.md index 84fda00c6..f3d0ac9bf 100755 --- a/README.md +++ b/README.md @@ -18,8 +18,7 @@ This client **only** supports Zendesk's API v2. Please see our [API documentati ## Requirements -* TODO: Update README -* PHP 5.5+ +* PHP 7.4+ ## Installation diff --git a/src/Zendesk/API/Resources/Chat/Apps.php b/src/Zendesk/API/Resources/Chat/Apps.php index 2d556d916..ea55efaf1 100644 --- a/src/Zendesk/API/Resources/Chat/Apps.php +++ b/src/Zendesk/API/Resources/Chat/Apps.php @@ -14,7 +14,7 @@ class Apps extends ResourceAbstract /** * @var string */ - protected $apiBasePath = 'api/chat/'; + protected $apiBasePath = ''; /** * {@inheritdoc} diff --git a/tests/Zendesk/API/UnitTests/BasicTest.php b/tests/Zendesk/API/UnitTests/BasicTest.php index 848eeaa5f..dc22b1f6b 100644 --- a/tests/Zendesk/API/UnitTests/BasicTest.php +++ b/tests/Zendesk/API/UnitTests/BasicTest.php @@ -185,9 +185,8 @@ public function assertRequestIs($options, $index = 0) if (isset($options['apiBasePath'])) { $this->assertSame( - 0, - strpos($request->getUri()->getPath(), $options['apiBasePath']), - "Failed asserting that the API basepath is {$options['apiBasePath']}" + 0, strpos($request->getUri()->getPath(), $options['apiBasePath']), + "Failed asserting apiBasePath: expected: {$options['apiBasePath']}, actual: {$request->getUri()->getPath()}" ); } @@ -195,7 +194,9 @@ public function assertRequestIs($options, $index = 0) // Truncate the base path from the target, this was added since the existing usage pattern for // $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); + $this->assertEquals( + $options['endpoint'], $endpoint, + "Failed asserting endpoint: expected: {$options['endpoint']}, actual: {$endpoint}"); } if (isset($options['queryParams'])) { diff --git a/tests/Zendesk/API/UnitTests/Chat/AppsTest.php b/tests/Zendesk/API/UnitTests/Chat/AppsTest.php index 72cd496de..844d96c32 100644 --- a/tests/Zendesk/API/UnitTests/Chat/AppsTest.php +++ b/tests/Zendesk/API/UnitTests/Chat/AppsTest.php @@ -12,11 +12,10 @@ class AppsTest extends BasicTest */ public function testInstall() { - $this->markTestSkipped('CBP TODO'); - $faker = Factory::create(); $postFields = [ 'app_id' => $faker->numberBetween(1), + 'product_name' => 'chat', 'settings' => [ 'name' => $faker->word, @@ -28,7 +27,7 @@ public function testInstall() $this->client->chat->apps()->install($postFields); }, 'apps/installations.json', 'POST', [ 'postFields' => $postFields, - 'apiBasePath' => '/api/chat/', + 'apiBasePath' => '/api/v2/' ]); } } diff --git a/tests/Zendesk/API/UnitTests/Core/AuthTest.php b/tests/Zendesk/API/UnitTests/Core/AuthTest.php index 71fde21ff..de8c1c08b 100755 --- a/tests/Zendesk/API/UnitTests/Core/AuthTest.php +++ b/tests/Zendesk/API/UnitTests/Core/AuthTest.php @@ -20,7 +20,7 @@ class AuthTest extends BasicTest */ public function testAnonymousAccess() { - $this->markTestSkipped('CBP TODO'); + $this->markTestSkipped('Broken in PHP 7.4 (mocking)'); // mock client $client = $this @@ -40,7 +40,7 @@ public function testAnonymousAccess() // send request $client->guzzle = $this->getMockBuilder(Client::class)->getMock(); - $client->guzzle->method('send')->willReturn(new Response); + $client->guzzle->method('send')->willReturn(new Response(200, [], '')); Http::send($client, ''); } diff --git a/tests/Zendesk/API/UnitTests/Core/SatisfactionRatingsTest.php b/tests/Zendesk/API/UnitTests/Core/SatisfactionRatingsTest.php index 64e895024..b218f0d30 100755 --- a/tests/Zendesk/API/UnitTests/Core/SatisfactionRatingsTest.php +++ b/tests/Zendesk/API/UnitTests/Core/SatisfactionRatingsTest.php @@ -42,24 +42,19 @@ function () use ($ticketId, $postParams) { /** * Test the create method requires a ticket id - * - * XexpectedException Zendesk\API\Exceptions\MissingParametersException - * XexpectedExceptionMessage Missing parameters: 'ticket_id' must be supplied for Zendesk\API\Resources\Core\SatisfactionRatings::create */ public function testCreateNeedsTicketId() { - $this->markTestSkipped('CBP TODO'); - // replace X with @ above - $postParams = [ 'score' => 'good', 'comment' => 'Awesome Support!', ]; + $this->setExpectedException( + 'Zendesk\API\Exceptions\MissingParametersException', + "Missing parameters: 'ticket_id' must be supplied for Zendesk\API\Resources\Core\SatisfactionRatings::create" + ); + $this->client->satisfactionRatings()->create($postParams); } } -// 2) Zendesk\API\UnitTests\Core\SatisfactionRatingsTest::testCreateNeedsTicketId -// count(): Parameter must be an array or an object that implements Countable -// -// phpvfscomposer:///app/vendor/phpunit/phpunit/phpunit:35 diff --git a/tests/Zendesk/API/UnitTests/Embeddable/ConfigSetsTest.php b/tests/Zendesk/API/UnitTests/Embeddable/ConfigSetsTest.php index 9b3269599..b86210551 100644 --- a/tests/Zendesk/API/UnitTests/Embeddable/ConfigSetsTest.php +++ b/tests/Zendesk/API/UnitTests/Embeddable/ConfigSetsTest.php @@ -40,7 +40,6 @@ public function testUpdate() $this->assertEndpointCalled(function () use ($params, $id) { $this->client->embeddable->configSets()->update($id, $params); - // TODO: Verify calls work }, "api/v2/embeddable/api/config_sets/{$id}.json", 'PUT', [ 'apiBasePath' => '/', 'postFields' => ['config_set' => $params], diff --git a/tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php b/tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php index 63db7965e..073c7995b 100644 --- a/tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php +++ b/tests/Zendesk/API/UnitTests/Exceptions/ApiResponseExceptionTest.php @@ -12,7 +12,7 @@ class ApiResponseExceptionTest extends BasicTest */ public function testPreviousException() { - $this->markTestSkipped('CBP TODO'); + $this->markTestSkipped('Broken in PHP 7.4 (mocking)'); $message = 'The previous exception was not passed to ApiResponseException'; $mockException = $this diff --git a/tests/Zendesk/API/UnitTests/HttpTest.php b/tests/Zendesk/API/UnitTests/HttpTest.php index 060fb0887..bfad14619 100644 --- a/tests/Zendesk/API/UnitTests/HttpTest.php +++ b/tests/Zendesk/API/UnitTests/HttpTest.php @@ -19,16 +19,15 @@ class HttpTest extends BasicTest */ public function testOriginalRequestExceptionIsPreserved() { - $this->markTestSkipped('CBP TODO'); - + $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(); + ->disableOriginalConstructor() + ->getMock(); $guzzleClient->expects($this->once()) ->method('send') ->will($this->throwException($exception)); @@ -70,14 +69,14 @@ public function testOriginalRequestExceptionIsPreserved() private function mockRequestException($message) { $request = $this->getMockBuilder(Request::class) - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $response = $this->getMockBuilder(Response::class) - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $body = $this->getMockBuilder(Stream::class) - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $request->method('getBody') ->will($this->returnValue($body)); $response->method('getBody') diff --git a/tests/Zendesk/API/UnitTests/Middleware/RetryHandlerTest.php b/tests/Zendesk/API/UnitTests/Middleware/RetryHandlerTest.php index ed25cd3a5..ecf5292b2 100644 --- a/tests/Zendesk/API/UnitTests/Middleware/RetryHandlerTest.php +++ b/tests/Zendesk/API/UnitTests/Middleware/RetryHandlerTest.php @@ -55,7 +55,6 @@ public function requestExceptionsProvider() return [ [ServerException::class, true], [ClientException::class, true], - // TODO: [ConnectException::class, false], [TooManyRedirectsException::class, false] ]; } @@ -205,15 +204,11 @@ public function retryDelayProvider() */ public function testHttpClientRetry() { - $this->markTestSkipped('CBP TODO'); - $this->setUp(); $config = $this->client->guzzle->getConfig(); $sslException = new RequestException( 'ssl', - $this->getMockBuilder(Request::class) - ->disableOriginalConstructor() - ->getMock() + new Request('GET', '') ); $mock = new MockHandler([ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 52477cad7..44b74ede4 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,8 +1,7 @@