class ClusterManagerTest in Elasticsearch Connector 8.7
Same name and namespace in other branches
- 8.5 tests/src/Unit/ClusterManagerTest.php \Drupal\Tests\elasticsearch_connector\Unit\ClusterManagerTest
- 8.6 tests/src/Unit/ClusterManagerTest.php \Drupal\Tests\elasticsearch_connector\Unit\ClusterManagerTest
@coversDefaultClass \Drupal\elasticsearch_connector\ClusterManager
@group elasticsearch_connector
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\elasticsearch_connector\Unit\ClusterManagerTest
Expanded class hierarchy of ClusterManagerTest
File
- tests/
src/ Unit/ ClusterManagerTest.php, line 17
Namespace
Drupal\Tests\elasticsearch_connector\UnitView 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
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClusterManagerTest:: |
protected | property | An instance of ClusterManager | |
ClusterManagerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ClusterManagerTest:: |
public | function | @covers ::__construct | |
ClusterManagerTest:: |
public | function | @covers ::getDefaultCluster @covers ::setDefaultCluster | |
ClusterManagerTest:: |
public | function | @covers ::loadAllClusters | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |