Skip to content
Snippets Groups Projects
Commit 288d4ebb 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 7ac1cabc
No related branches found
No related tags found
No related merge requests found
Pipeline #332483 failed
......@@ -53,15 +53,14 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
// Configure loadAllParents pour renvoyer la hiérarchie correcte selon l'ID.
$term_storage->method('loadAllParents')
->willReturnCallback(function ($term_id) use ($terms_to_view, $terms) {
// Find the index of the term ID.
foreach ($terms_to_view as $idx => $term_item) {
if ($term_item->id() === $term_id) {
return array_reverse($terms[$idx]);
}
->willReturnCallback(function ($term_id) use ($parentRelationships, $created) {
$parents = [];
while (isset($parentRelationships[$term_id])) {
$parent_id = $parentRelationships[$term_id];
$parents[] = $created[array_search($parent_id, array_column($created, 'id'))];
$term_id = $parent_id;
}
// return an empty table if the ID does not correspond.
return [];
return array_reverse($parents);
});
}
......@@ -108,22 +107,35 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
*/
protected function createTerms(array $tree): array {
$created = [];
// Array to store parent relationships.
$parentRelationships = [];
return array_map(function (array $lineage) use (&$created): array {
$terms = [];
return array_map(function (array $lineage) use (&$created, &$parentRelationships): array {
$terms = [];
foreach ($lineage as $name) {
if (!isset($created[$name])) {
$link = $this->createMock(Link::class);
$link->method('toString')->willReturn(static::getGeneratedLink($name));
$term = $this->createMock(TermInterface::class);
$term->method('id')->willReturn($this->getFixedTermId($name));
$term->method('label')->willReturn($name);
$term->method('toLink')->willReturn($link);
$created[$name] = $term;
$link = $this->createMock(Link::class);
$link->method('toString')->willReturn(static::getGeneratedLink($name));
$term = $this->createMock(TermInterface::class);
$term->method('id')->willReturn($this->getFixedTermId($name));
$term->method('label')->willReturn($name);
$term->method('toLink')->willReturn($link);
$created[$name] = $term;
}
$terms[] = $created[$name];
}
// Populate parent relationships.
foreach (array_reverse($lineage) as $index => $name) {
$parent = next($lineage);
if ($parent) {
$parentRelationships[$created[$name]->id()] = $created[$parent]->id();
}
$terms[] = $created[$name];
}
return $terms;
return $terms;
}, $tree);
}
......
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