protected function GraphTest::assertComponents in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Component/Graph/GraphTest.php \Drupal\Tests\Component\Graph\GraphTest::assertComponents()
- 9 core/tests/Drupal/Tests/Component/Graph/GraphTest.php \Drupal\Tests\Component\Graph\GraphTest::assertComponents()
Verify expected components in a graph.
@internal
Parameters
array $graph: A graph array processed by \Drupal\Component\Graph\Graph::searchAndSort().
array $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 - Tests depth-first-search features.
File
- core/
tests/ Drupal/ Tests/ Component/ Graph/ GraphTest.php, line 152
Class
- GraphTest
- @coversDefaultClass \Drupal\Component\Graph\Graph @group Graph
Namespace
Drupal\Tests\Component\GraphCode
protected function assertComponents(array $graph, array $expected_components) : void {
$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)));
}