You are here

class ClientManagerTest in Elasticsearch Connector 8.5

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

@coversDefaultClass \Drupal\elasticsearch_connector\ElasticSearch\ClientManager

@group elasticsearch_connector

Hierarchy

Expanded class hierarchy of ClientManagerTest

File

tests/src/Unit/ElasticSearch/ClientManagerTest.php, line 18

Namespace

Drupal\Tests\elasticsearch_connector\Unit\ElasticSearch
View source
class ClientManagerTest extends UnitTestCase {

  /**
   * An instance of ClientManager
   *
   * @var \Drupal\elasticsearch_connector\ElasticSearch\ClientManager
   */
  protected $clientManager;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $module_handler = $this
      ->prophesize(ModuleHandlerInterface::class);
    $client_factory = $this
      ->prophesize(ClientFactoryInterface::class);
    $client_factory
      ->create(Argument::type('array'))
      ->willReturn($this
      ->prophesize(ClientInterface::class)
      ->reveal());
    $this->clientManager = new ClientManager($module_handler
      ->reveal(), $client_factory
      ->reveal());
  }

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

  /**
   * @covers ::getClientForCluster
   */
  public function testGetClientForCluster() {
    $cluster = $this
      ->prophesize(Cluster::class);
    $cluster
      ->getRawUrl()
      ->willReturn('http://example.com');
    $cluster = $cluster
      ->reveal();
    $cluster->options['use_authentication'] = TRUE;
    $cluster->options['username'] = 'Tom';
    $cluster->options['password'] = 'Waits';
    $cluster->options['authentication_type'] = 'basic_auth';
    $client = $this->clientManager
      ->getClientForCluster($cluster);
    $this
      ->assertInstanceOf(ClientInterface::class, $client);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClientManagerTest::$clientManager protected property An instance of ClientManager
ClientManagerTest::setUp protected function Overrides UnitTestCase::setUp
ClientManagerTest::testConstruct public function @covers ::__construct
ClientManagerTest::testGetClientForCluster public function @covers ::getClientForCluster
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.