You are here

class ClusterManagerTest in Elasticsearch Connector 8.7

Same name and namespace in other branches
  1. 8.5 tests/src/Unit/ClusterManagerTest.php \Drupal\Tests\elasticsearch_connector\Unit\ClusterManagerTest
  2. 8.6 tests/src/Unit/ClusterManagerTest.php \Drupal\Tests\elasticsearch_connector\Unit\ClusterManagerTest

@coversDefaultClass \Drupal\elasticsearch_connector\ClusterManager

@group elasticsearch_connector

Hierarchy

Expanded class hierarchy of ClusterManagerTest

File

tests/src/Unit/ClusterManagerTest.php, line 17

Namespace

Drupal\Tests\elasticsearch_connector\Unit
View source
class ClusterManagerTest extends UnitTestCase {

  /**
   * An instance of ClusterManager
   *
   * @var \Drupal\elasticsearch_connector\ClusterManager
   */
  protected $clusterManager;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $state = $this
      ->prophesize(StateInterface::class);
    $entity_type_manager = $this
      ->prophesize(EntityTypeManagerInterface::class);
    $this->clusterManager = new ClusterManager($state
      ->reveal(), $entity_type_manager
      ->reveal());
  }

  /**
   * @covers ::__construct
   */
  public function testConstruct() {
    $this
      ->assertInstanceOf(ClusterManager::class, $this->clusterManager);
  }

  /**
   * @covers ::getDefaultCluster
   * @covers ::setDefaultCluster
   */
  public function testGetSetDefaultCluster() {
    $state = $this
      ->prophesize(StateInterface::class);
    $state
      ->get('elasticsearch_connector_get_default_connector', '')
      ->willReturn('foo');
    $state
      ->set('elasticsearch_connector_get_default_connector', 'foo')
      ->shouldBeCalled();

    // Check the get method.
    $entity_type_manager = $this
      ->prophesize(EntityTypeManagerInterface::class);
    $this->clusterManager = new ClusterManager($state
      ->reveal(), $entity_type_manager
      ->reveal());
    $this
      ->assertEquals('foo', $this->clusterManager
      ->getDefaultCluster());

    // Check the set method (a prediction was set above).
    $this->clusterManager
      ->setDefaultCluster('foo');
  }

  /**
   * @covers ::loadAllClusters
   */
  public function testLoadAllClusters() {
    $state = $this
      ->prophesize(StateInterface::class);
    $cluster1 = new \stdClass();
    $cluster1->cluster_id = 'foo';
    $cluster1->status = FALSE;
    $cluster2 = new \stdClass();
    $cluster2->cluster_id = 'bar';
    $cluster2->status = TRUE;
    $entity_storage_interface = $this
      ->prophesize(EntityStorageInterface::class);
    $entity_storage_interface
      ->loadMultiple()
      ->willReturn([
      $cluster1->cluster_id => $cluster1,
      $cluster2->cluster_id => $cluster2,
    ]);
    $entity_type_manager = $this
      ->prophesize(EntityTypeManagerInterface::class);
    $entity_type_manager
      ->getStorage('elasticsearch_cluster')
      ->willReturn($entity_storage_interface
      ->reveal());
    $this->clusterManager = new ClusterManager($state
      ->reveal(), $entity_type_manager
      ->reveal());
    $expected_clusters = [
      $cluster2->cluster_id => $cluster2,
    ];
    $this
      ->assertEquals($expected_clusters, $this->clusterManager
      ->loadAllClusters(FALSE));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClusterManagerTest::$clusterManager protected property An instance of ClusterManager
ClusterManagerTest::setUp protected function Overrides UnitTestCase::setUp
ClusterManagerTest::testConstruct public function @covers ::__construct
ClusterManagerTest::testGetSetDefaultCluster public function @covers ::getDefaultCluster @covers ::setDefaultCluster
ClusterManagerTest::testLoadAllClusters public function @covers ::loadAllClusters
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.