function GraphTest::assertComponents
Same name in other branches
- 9 core/tests/Drupal/Tests/Component/Graph/GraphTest.php \Drupal\Tests\Component\Graph\GraphTest::assertComponents()
- 10 core/tests/Drupal/Tests/Component/Graph/GraphTest.php \Drupal\Tests\Component\Graph\GraphTest::assertComponents()
- 11.x 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 144
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 = [];
foreach ($component as $vertex) {
$result_components[] = $graph[$vertex]['component'];
unset($unassigned_vertices[$vertex]);
}
$this->assertCount(1, array_unique($result_components), sprintf('Expected one unique component for vertices %s, got %s', $this->displayArray($component), $this->displayArray($result_components)));
}
$this->assertEquals([], $unassigned_vertices, sprintf('Vertices not assigned to a component: %s', $this->displayArray($unassigned_vertices, TRUE)));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.