protected function GraphTest::assertComponents in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Component/Graph/GraphTest.php \Drupal\Tests\Component\Graph\GraphTest::assertComponents()
Verify expected components in a graph.
Parameters
$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.
1 call to GraphTest::assertComponents()
- GraphTest::testDepthFirstSearch in core/
tests/ Drupal/ Tests/ Component/ Graph/ GraphTest.php - Test depth-first-search features.
File
- core/
tests/ Drupal/ Tests/ Component/ Graph/ GraphTest.php, line 149 - Contains \Drupal\Tests\Component\Graph\GraphTest.
Class
- GraphTest
- @coversDefaultClass \Drupal\Component\Graph\Graph @group Graph
Namespace
Drupal\Tests\Component\GraphCode
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)));
}