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

Issue #3455186 by joseph.olstad - 3rd broken Refactor of 88f1e040 for...

Issue #3455186 by joseph.olstad - 3rd broken Refactor of 88f1e040 for tests for D11 phpunit 10+ compatibility refactoring test.
parent f8b7d7de
No related branches found
No related tags found
No related merge requests found
Pipeline #333344 failed
......@@ -47,73 +47,71 @@ 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 {
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;
}
// 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([]);
}
};
$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);
}
return $terms;
}, $tree);
// Traverse the lineage from the end to set parents.
$reverse = \array_reverse($lineage);
......
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