You are here

public function RestClientTest::testReauthApiCall 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::testReauthApiCall()
  2. 5.0.x tests/src/Unit/RestClientTest.php \Drupal\Tests\salesforce\Unit\RestClientTest::testReauthApiCall()

@covers ::apiCall

File

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

Class

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

Namespace

Drupal\Tests\salesforce\Unit

Code

public function testReauthApiCall() {
  $this
    ->initClient();

  // Test that apiCall does auto-re-auth after 401 response.
  $response_401 = new GuzzleResponse(401);
  $response_200 = new GuzzleResponse(200);

  // First httpRequest() is position 4.
  // @TODO this is extremely brittle, exposes complexity in underlying client. Refactor this.
  $this->client
    ->expects($this
    ->at(3))
    ->method('httpRequest')
    ->willReturn($response_401);
  $this->client
    ->expects($this
    ->at(4))
    ->method('httpRequest')
    ->willReturn($response_200);
  $this->client
    ->apiCall('');
}