You are here

public function AutoConnectorTest::testAutoConnect in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/AutoConnectorTest.php \Drupal\Tests\acquia_connector\Unit\AutoConnectorTest::testAutoConnect()
  2. 3.x tests/src/Unit/AutoConnectorTest.php \Drupal\Tests\acquia_connector\Unit\AutoConnectorTest::testAutoConnect()

Tests the happy path.

  • when there is not current connection (stored credentials)
  • attempt to connect succeeds.

File

tests/src/Unit/AutoConnectorTest.php, line 23

Class

AutoConnectorTest
@coversDefaultClass \Drupal\acquia_connector\AutoConnector

Namespace

Drupal\Tests\acquia_connector\Unit

Code

public function testAutoConnect() {
  $subscription_mock = $this
    ->prophesize(Subscription::CLASS);
  $subscription_mock
    ->hasCredentials()
    ->willReturn(FALSE);
  $subscription_mock
    ->update()
    ->willReturn(TRUE);
  $storage_mock = $this
    ->prophesize(Storage::CLASS);
  $config = [
    'ah_network_identifier' => 'WXYZ-12345',
    'ah_network_key' => '12345678901234567890',
  ];
  $auto_connector = new AutoConnector($subscription_mock
    ->reveal(), $storage_mock
    ->reveal(), $config);
  $auto_connected = $auto_connector
    ->connectToAcquia();
  $this
    ->assertTrue($auto_connected);
  $storage_mock
    ->setKey('12345678901234567890')
    ->shouldHaveBeenCalled();
  $storage_mock
    ->setIdentifier('WXYZ-12345')
    ->shouldHaveBeenCalled();
  $subscription_mock
    ->update()
    ->shouldHaveBeenCalled();
}