You are here

public function ApigeeEdgeManagementCliServiceTest::testCreateEdgeRoleForDrupalWhenRoleExistsTestNoForceFlag in Apigee Edge 8

If force parameter is not passed in, do not mess with a role that exists.

File

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

Class

ApigeeEdgeManagementCliServiceTest
Test ApigeeEdgeManagementCliService.

Namespace

Drupal\Tests\apigee_edge\Unit\Command\Util

Code

public function testCreateEdgeRoleForDrupalWhenRoleExistsTestNoForceFlag() {

  // Expected to output error if role does not exist.
  $io = $this
    ->prophesize(StyleInterface::class);
  $io
    ->success(Argument::exact('Connected to Edge org ' . $this->org . '.'))
    ->shouldBeCalledTimes(1);
  $io
    ->error(Argument::containingString('Role ' . $this->roleName . ' already exists.'))
    ->shouldBeCalledTimes(1);
  $io
    ->note(Argument::containingString('Run with --force option'))
    ->shouldBeCalled();

  // Return organization info.
  $response_org = $this
    ->prophesize(Response::class);
  $response_org
    ->getBody()
    ->shouldBeCalledTimes(1)
    ->willReturn('{ "name": "' . $this->org . '" }');
  $this->httpClient
    ->get(Argument::exact($this->baseUrl . '/o/' . $this->org), Argument::type('array'))
    ->shouldBeCalledTimes(1)
    ->willReturn($response_org
    ->reveal());

  // Return existing role.
  $response_user_role = $this
    ->prophesize(Response::class);
  $response_user_role
    ->getBody()
    ->willReturn('{ "name": "' . $this->roleName . '" }');
  $this->httpClient
    ->get(Argument::exact($this->baseUrl . '/o/' . $this->org . '/userroles/' . $this->roleName), Argument::type('array'))
    ->willReturn($response_user_role
    ->reveal());
  $apigee_edge_management_cli_service = new ApigeeEdgeManagementCliService($this->httpClient
    ->reveal());
  $apigee_edge_management_cli_service
    ->createEdgeRoleForDrupal($io
    ->reveal(), [
    $this,
    'mockDt',
  ], $this->org, $this->email, $this->password, $this->baseUrl, $this->roleName, FALSE);
}