You are here

public function RestClientTest::testObjectDelete in Salesforce Suite 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Unit/RestClientTest.php \Drupal\Tests\salesforce\Unit\RestClientTest::testObjectDelete()
  2. 5.0.x tests/src/Unit/RestClientTest.php \Drupal\Tests\salesforce\Unit\RestClientTest::testObjectDelete()

@covers ::objectDelete

@expectedException \GuzzleHttp\Exception\RequestException

File

tests/src/Unit/RestClientTest.php, line 400

Class

RestClientTest
@coversDefaultClass \Drupal\salesforce\Rest\RestClient @group salesforce

Namespace

Drupal\Tests\salesforce\Unit

Code

public function testObjectDelete() {
  $this
    ->initClient(array_merge($this->methods, [
    'apiCall',
  ]));

  // 3 tests for objectDelete:
  // 1. test that a successful delete returns null
  // 2. test that a 404 response gets eaten
  // 3. test that any other error response percolates.
  $this->client
    ->expects($this
    ->exactly(3))
    ->method('apiCall');
  $this->client
    ->expects($this
    ->at(0))
    ->method('apiCall')
    ->willReturn(NULL);
  $exception404 = new RequestException('', new GuzzleRequest('GET', ''), new GuzzleResponse(404, [], ''));
  $this->client
    ->expects($this
    ->at(1))
    ->method('apiCall')
    ->will($this
    ->throwException($exception404));

  // Test the objectDelete throws any other exception.
  $exceptionOther = new RequestException('', new GuzzleRequest('GET', ''), new GuzzleResponse(456, [], ''));
  $this->client
    ->expects($this
    ->at(2))
    ->method('apiCall')
    ->will($this
    ->throwException($exceptionOther));
  $this
    ->assertNull($this->client
    ->objectDelete('', ''));
  $this
    ->assertNull($this->client
    ->objectDelete('', ''));
  $this->client
    ->objectDelete('', '');
}