Verify expected components in a graph.
$graph: A graph array processed by \Drupal\Component\Graph\Graph::searchAndSort().
$expected_components: An array containing of components defined as a list of their vertices.
protected function assertComponents($graph, $expected_components) {
$unassigned_vertices = array_fill_keys(array_keys($graph), TRUE);
foreach ($expected_components as $component) {
$result_components = array();
foreach ($component as $vertex) {
$result_components[] = $graph[$vertex]['component'];
unset($unassigned_vertices[$vertex]);
}
$this
->assertEquals(1, count(array_unique($result_components)), sprintf('Expected one unique component for vertices %s, got %s', $this
->displayArray($component), $this
->displayArray($result_components)));
}
$this
->assertEquals(array(), $unassigned_vertices, sprintf('Vertices not assigned to a component: %s', $this
->displayArray($unassigned_vertices, TRUE)));
}