Skip to content
Snippets Groups Projects
Commit cce95cbe 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 5c9fc1b7
No related branches found
No related tags found
No related merge requests found
Pipeline #332488 failed
......@@ -51,19 +51,16 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
foreach ($terms_to_view as $index => $term) {
$expected_parents = array_reverse($terms[$index]);
// Adjust the loadAllParents mock callback to handle missing parents gracefully.
// Mock the `loadAllParents` method with proper null handling.
$term_storage->method('loadAllParents')
->willReturnCallback(function ($term_id) use ($parentRelationships, $created) {
$parents = [];
while (isset($parentRelationships[$term_id])) {
while (isset($parentRelationships[$term_id]) && isset($created[$parentRelationships[$term_id]])) {
$parent_id = $parentRelationships[$term_id];
if (isset($created[array_search($parent_id, array_column($created, 'id'))])) {
$parents[] = $created[$parent_id];
}
$parents[] = $created[$parent_id];
$term_id = $parent_id;
}
// Return parents array after filtering any nulls.
return array_filter(array_reverse($parents));
return array_reverse($parents);
});
}
......@@ -113,7 +110,6 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
// Array to store parent relationships.
$parentRelationships = [];
// Create terms based on the hierarchy tree and store parent relationships.
return array_map(function (array $lineage) use (&$created, &$parentRelationships): array {
$terms = [];
foreach ($lineage as $name) {
......@@ -134,7 +130,7 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
// Store parent relationships for the reversed lineage.
$parent = NULL;
foreach (array_reverse($lineage) as $name) {
if ($parent) {
if ($parent && isset($created[$name])) {
$parentRelationships[$created[$name]->id()] = $parent->id();
}
$parent = $created[$name];
......
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