You are here

class AutoConnectorTest 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
  2. 3.x tests/src/Unit/AutoConnectorTest.php \Drupal\Tests\acquia_connector\Unit\AutoConnectorTest

@coversDefaultClass \Drupal\acquia_connector\AutoConnector

@group Acquia connector

Hierarchy

Expanded class hierarchy of AutoConnectorTest

File

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

Namespace

Drupal\Tests\acquia_connector\Unit
View source
class AutoConnectorTest extends UnitTestCase {

  /**
   * Tests the happy path.
   *
   *  - when there is not current connection (stored credentials)
   *  - attempt to connect succeeds.
   */
  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();
  }

  /**
   * Tests the scenario when the site is already connected to Acquia.
   */
  public function testAutoConnectWhenAlreadyConnected() {
    $subscription_mock = $this
      ->prophesize(Subscription::CLASS);
    $subscription_mock
      ->hasCredentials()
      ->willReturn(TRUE);
    $subscription_mock
      ->update()
      ->shouldNotBeCalled();
    $storage_mock = $this
      ->prophesize(Storage::CLASS);
    $storage_mock
      ->setKey()
      ->shouldNotBeCalled();
    $storage_mock
      ->setIdentifier()
      ->shouldNotBeCalled();
    $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
      ->assertFalse($auto_connected);
  }

  /**
   * Tests auto connect.
   *
   * Tests the scenario when the site is not connected but there are no
   * credentials provided by the global config.
   */
  public function testAutoConnectWhenNoCredsInGlobalConfig() {
    $subscription_mock = $this
      ->prophesize(Subscription::CLASS);
    $subscription_mock
      ->hasCredentials()
      ->willReturn(FALSE);
    $subscription_mock
      ->update()
      ->shouldNotBeCalled();
    $storage_mock = $this
      ->prophesize(Storage::CLASS);
    $storage_mock
      ->setKey()
      ->shouldNotBeCalled();
    $storage_mock
      ->setIdentifier()
      ->shouldNotBeCalled();
    $config = [];
    $auto_connector = new AutoConnector($subscription_mock
      ->reveal(), $storage_mock
      ->reveal(), $config);
    $auto_connected = $auto_connector
      ->connectToAcquia();
    $this
      ->assertFalse($auto_connected);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AutoConnectorTest::testAutoConnect public function Tests the happy path.
AutoConnectorTest::testAutoConnectWhenAlreadyConnected public function Tests the scenario when the site is already connected to Acquia.
AutoConnectorTest::testAutoConnectWhenNoCredsInGlobalConfig public function Tests auto connect.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340