You are here

protected function GraphTest::assertPaths in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Graph/GraphTest.php \Drupal\Tests\Component\Graph\GraphTest::assertPaths()
  2. 9 core/tests/Drupal/Tests/Component/Graph/GraphTest.php \Drupal\Tests\Component\Graph\GraphTest::assertPaths()

Verify expected paths in a graph.

@internal

Parameters

array $graph: A graph array processed by \Drupal\Component\Graph\Graph::searchAndSort()

array $expected_paths: An associative array containing vertices with their expected paths.

1 call to GraphTest::assertPaths()
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 113

Class

GraphTest
@coversDefaultClass \Drupal\Component\Graph\Graph @group Graph

Namespace

Drupal\Tests\Component\Graph

Code

protected function assertPaths(array $graph, array $expected_paths) : void {
  foreach ($expected_paths as $vertex => $paths) {

    // Build an array with keys = $paths and values = TRUE.
    $expected = array_fill_keys($paths, TRUE);
    $result = $graph[$vertex]['paths'] ?? [];
    $this
      ->assertEquals($expected, $result, sprintf('Expected paths for vertex %s: %s, got %s', $vertex, $this
      ->displayArray($expected, TRUE), $this
      ->displayArray($result, TRUE)));
  }
}