Skip to content
Snippets Groups Projects
Commit fda1ad95 authored by Joseph Olstad's avatar Joseph Olstad
Browse files

Issue #3455186 by cmlara, joseph.olstad - Refactor tests for D11 phpunit 10+...

Issue #3455186 by cmlara, joseph.olstad - Refactor tests for D11 phpunit 10+ compatibility refactoring test.
parent cce95cbe
No related branches found
No related tags found
No related merge requests found
Pipeline #332507 failed
......@@ -51,14 +51,17 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
foreach ($terms_to_view as $index => $term) {
$expected_parents = array_reverse($terms[$index]);
// Mock the `loadAllParents` method with proper null handling.
// Mock the `loadAllParents` method.
$term_storage->method('loadAllParents')
->willReturnCallback(function ($term_id) use ($parentRelationships, $created) {
->willReturnCallback(function ($term_id) use ($parentRelationships) {
$parents = [];
while (isset($parentRelationships[$term_id]) && isset($created[$parentRelationships[$term_id]])) {
$parent_id = $parentRelationships[$term_id];
$parents[] = $created[$parent_id];
$term_id = $parent_id;
while (isset($parentRelationships[$term_id])) {
$parent = $parentRelationships[$term_id];
if ($parent === NULL) {
break;
}
$parents[] = $parent;
$term_id = $parent->id();
}
return array_reverse($parents);
});
......@@ -107,9 +110,9 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
*/
protected function createTerms(array $tree): array {
$created = [];
// Array to store parent relationships.
$parentRelationships = [];
// Create mock terms based on the hierarchy tree.
return array_map(function (array $lineage) use (&$created, &$parentRelationships): array {
$terms = [];
foreach ($lineage as $name) {
......@@ -127,13 +130,13 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
$terms[] = $created[$name];
}
// Store parent relationships for the reversed lineage.
$parent = NULL;
foreach (array_reverse($lineage) as $name) {
if ($parent && isset($created[$name])) {
$parentRelationships[$created[$name]->id()] = $parent->id();
// Establish parent relationships.
$previous = NULL;
foreach ($terms as $term) {
if ($previous) {
$parentRelationships[$term->id()] = $previous;
}
$parent = $created[$name];
$previous = $term;
}
return $terms;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment