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

Issue #3455186 by joseph.olstad - Refactor of 88f1e040 for tests for D11...

Issue #3455186 by joseph.olstad - Refactor of 88f1e040 for tests for D11 phpunit 10+ compatibility refactoring test.
parent b3d28f4d
No related branches found
No related tags found
No related merge requests found
Pipeline #333374 failed
......@@ -47,71 +47,41 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
return $settings[$name] ?? NULL;
});
$terms = \array_map(function (array $lineage) {
static $created = [];
$terms = [];
$terms = \array_map(function (array $lineage) {
static $created = [];
$terms = [];
foreach ($lineage as $name) {
foreach ($lineage as $name) {
if (!isset($created[$name])) {
$link = $this->createMock(Link::class);
$link->method('toString')->willReturn(static::getGeneratedLink($name));
// Create an anonymous class that extends TermInterface and adds set/get methods for parent
$term = new class($name, $link) implements TermInterface, \IteratorAggregate {
private $id;
private $label;
private $link;
private $parent;
public function __construct($label, $link) {
$this->id = \random_int(1, 10000);
$this->label = $label;
$this->link = $link;
}
public function id() {
return $this->id;
}
public function label() {
return $this->label;
}
public function toLink($text = null, $rel = 'canonical', array $options = []) {
return $this->link;
}
// Implementing the parent methods
public function setParent($parent) {
$this->parent = $parent;
}
public function getParent() {
return $this->parent;
}
// Implementing IteratorAggregate
public function getIterator(): \Traversable {
return new \ArrayIterator([]);
}
};
// Create a partial mock of TermInterface.
$term = $this->getMockForAbstractClass(TermInterface::class, [], '', FALSE, TRUE, TRUE, [
'id', 'label', 'toLink', 'getDescription', 'setDescription',
]);
$term->method('id')->willReturn(\random_int(1, 10000));
$term->method('label')->willReturn($name);
$term->method('toLink')->willReturn($link);
$term->method('getDescription')->willReturn('Description for ' . $name);
$term->method('setDescription')->willReturn(NULL);
$created[$name] = $term;
}
$terms[] = $created[$name];
}
}
// Traverse the lineage from the end to set parents.
$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]->setParent($parent_item);
}
// Traverse the lineage from the end to set parents.
$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;
}
return $terms;
}, $tree);
return $terms;
}, $tree);
// Set terms to view.
$terms_to_view = \array_map(static fn (array $lineage) => \end($lineage), $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