public function MultigraphUnitTest::testCalculateDependencies in Monitoring 8
@covers ::calculateDependencies
File
- modules/
multigraph/ tests/ src/ Unit/ Entity/ MultigraphUnitTest.php, line 40
Class
- MultigraphUnitTest
- @coversDefaultClass \Drupal\monitoring_multigraph\Entity\Multigraph
Namespace
Drupal\Tests\monitoring_multigraph\Unit\EntityCode
public function testCalculateDependencies() {
// Mock a couple of sensors.
$sensor1_id = $this
->getRandomGenerator()
->word(16);
$sensor1 = $this
->getMockSensor($sensor1_id);
$sensor2_id = $this
->getRandomGenerator()
->word(16);
$sensor2 = $this
->getMockSensor($sensor2_id);
// Create a Multigraph containing the sensors.
$multigraph = new Multigraph(array(
'sensors' => array(
$sensor1_id => array(
'weight' => 0,
'label' => '',
),
$sensor2_id => array(
'weight' => 1,
'label' => '',
),
),
), 'monitoring_multigraph');
// Mock whatever is used in calculateDependencies().
$sensor_storage = $this
->createMock(ConfigEntityStorageInterface::class);
$sensor_storage
->expects($this
->any())
->method('load')
->willReturnMap(array(
array(
$sensor1_id,
$sensor1,
),
array(
$sensor2_id,
$sensor2,
),
));
$this->entityTypeManager
->expects($this
->any())
->method('getStorage')
->with('monitoring_sensor_config')
->willReturn($sensor_storage);
// Assert dependencies are calculated correctly for the Multigraph.
$dependencies = $multigraph
->calculateDependencies();
$this
->assertEquals(array(
'entity' => array(
"sensor.{$sensor1_id}",
"sensor.{$sensor2_id}",
),
), $dependencies);
}