You are here

public function ApigeeEdgeManagementCliServiceTest::testIsValidEdgeCredentialsBadEndpoint in Apigee Edge 8

Test isValidEdgeCredentials() bad endpoint response.

File

tests/src/Unit/Command/Util/ApigeeEdgeManagementCliServiceTest.php, line 259

Class

ApigeeEdgeManagementCliServiceTest
Test ApigeeEdgeManagementCliService.

Namespace

Drupal\Tests\apigee_edge\Unit\Command\Util

Code

public function testIsValidEdgeCredentialsBadEndpoint() {

  // Mimic a invalid response for the call to get org details.
  $body = "<h1>not json</h1>";
  $response = $this
    ->prophesize(Response::class);
  $response
    ->getBody()
    ->shouldBeCalledTimes(1)
    ->willReturn($body);

  // The user should see an error message.
  $io = $this
    ->prophesize(StyleInterface::class);
  $io
    ->error(Argument::containingString('Unable to parse response from GET'))
    ->shouldBeCalledTimes(1);
  $this->httpClient
    ->get(Argument::type('string'), Argument::type('array'))
    ->willReturn($response
    ->reveal());
  $apigee_edge_management_cli_service = new ApigeeEdgeManagementCliService($this->httpClient
    ->reveal());
  $is_valid_creds = $apigee_edge_management_cli_service
    ->isValidEdgeCredentials($io
    ->reveal(), [
    $this,
    'mockDt',
  ], $this->org, $this->email, $this->password, $this->baseUrl);

  // Assert return that creds are false.
  $this
    ->assertEquals(FALSE, $is_valid_creds, 'Credentials are not valid, should return false.');
}