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

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

Issue #3455186 by joseph.olstad - Refactor tests for D11 phpunit 10+ compatibility refactoring test.
parent 88f1e040
No related branches found
No related tags found
No related merge requests found
Pipeline #333329 failed
......@@ -47,30 +47,49 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
return $settings[$name] ?? NULL;
});
// Create terms with lineage.
$terms = \array_map(function (array $lineage) {
static $created = [];
$terms = [];
$terms = [];
foreach ($lineage as $name) {
if (!isset($created[$name])) {
$link = $this->createMock(Link::class);
$link->method('toString')->willReturn(static::getGeneratedLink($name));
$created[$name] = $this->createMock(TermInterface::class);
$created[$name]->method('id')->willReturn(\random_int(1, 10000));
$created[$name]->method('label')->willReturn($name);
$created[$name]->method('toLink')->willReturn($link);
// Create a mock for the TermInterface with additional methods for parent handling.
$term = $this->getMockBuilder(TermInterface::class)
->disableOriginalConstructor()
->onlyMethods(['id', 'label', 'toLink', 'setParent', 'getParent'])
->getMock();
$term->method('id')->willReturn(\random_int(1, 10000));
$term->method('label')->willReturn($name);
$term->method('toLink')->willReturn($link);
// Add properties for parent handling.
$parent = NULL;
$term->method('setParent')
->willReturnCallback(function ($parentItem) use (&$parent) {
$parent = $parentItem;
});
$term->method('getParent')
->willReturnCallback(function () use (&$parent) {
return $parent;
});
$created[$name] = $term;
}
$terms[] = $created[$name];
$terms[] = $created[$name];
}
// Assign parents in reverse order.
// Traverse the lineage from the end to set parents using the setter method.
$reverse = \array_reverse($lineage);
foreach ($reverse as $name) {
$parent_item = $this->createMock(EntityReferenceFieldItemListInterface::class);
$parent_item->target_id = ($parent = \next($reverse)) ? $created[$parent]->id() : NULL;
$created[$name]->parent = $parent_item;
$created[$name]->setParent($parent_item);
}
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