Skip to content

Commit

Permalink
Merge pull request #509 from zendesk/RED-1950-unskip-tests
Browse files Browse the repository at this point in the history
Red 1950 unskip tests
  • Loading branch information
ecoologic committed Oct 10, 2023
2 parents fb53b5f + ac68725 commit 0dd3ce1
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 49 deletions.
16 changes: 10 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Zendesk/API/Resources/Chat/Apps.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Apps extends ResourceAbstract
/**
* @var string
*/
protected $apiBasePath = 'api/chat/';
protected $apiBasePath = '';

/**
* {@inheritdoc}
Expand Down
9 changes: 5 additions & 4 deletions tests/Zendesk/API/UnitTests/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,18 @@ 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()}"
);
}

if (isset($options['endpoint'])) {
// 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'])) {
Expand Down
5 changes: 2 additions & 3 deletions tests/Zendesk/API/UnitTests/Chat/AppsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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/'
]);
}
}
4 changes: 2 additions & 2 deletions tests/Zendesk/API/UnitTests/Core/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, '');
}

Expand Down
15 changes: 5 additions & 10 deletions tests/Zendesk/API/UnitTests/Core/SatisfactionRatingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion tests/Zendesk/API/UnitTests/Embeddable/ConfigSetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions tests/Zendesk/API/UnitTests/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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')
Expand Down
7 changes: 1 addition & 6 deletions tests/Zendesk/API/UnitTests/Middleware/RetryHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function requestExceptionsProvider()
return [
[ServerException::class, true],
[ClientException::class, true],
// TODO: [ConnectException::class, false],
[TooManyRedirectsException::class, false]
];
}
Expand Down Expand Up @@ -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([
Expand Down
5 changes: 2 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php

// TODO: Don't fail using deprecated code
// error_reporting(E_ALL ^ E_DEPRECATED);
error_reporting(- 1);
// Don't fail using deprecated code
error_reporting(E_ALL ^ E_DEPRECATED);

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
Expand Down

0 comments on commit 0dd3ce1

Please sign in to comment.