You are here

public function ApigeeEdgeManagementCliServiceTest::testIsValidEdgeCredentialsUnauthorized in Apigee Edge 8

Test isValidEdgeCredentials() unauthorized response.

File

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

Class

ApigeeEdgeManagementCliServiceTest
Test ApigeeEdgeManagementCliService.

Namespace

Drupal\Tests\apigee_edge\Unit\Command\Util

Code

public function testIsValidEdgeCredentialsUnauthorized() {

  // Invalid password returns unauthorized 403.
  $request_role = $this
    ->prophesize(RequestInterface::class);
  $response_role = $this
    ->prophesize(Response::class);
  $response_role
    ->getStatusCode()
    ->willReturn(403);
  $exception = new ClientException('Unauthorized', $request_role
    ->reveal(), $response_role
    ->reveal());
  $this->httpClient
    ->get(Argument::exact($this->baseUrl . '/o/' . $this->org), Argument::type('array'))
    ->willThrow($exception)
    ->shouldBeCalledTimes(1);

  // The user should see an error message.
  $io = $this
    ->prophesize(StyleInterface::class);
  $io
    ->error(Argument::containingString('Error connecting to Apigee Edge'))
    ->shouldBeCalledTimes(1);
  $io
    ->note(Argument::containingString('may not have the orgadmin role for Apigee Edge org'))
    ->shouldBeCalledTimes(1);
  $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);
  $this
    ->assertEquals(FALSE, $is_valid_creds, 'Credentials are not valid, should return false.');
}