Skip to content
Snippets Groups Projects
Commit f8b7d7de 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 27c5cea0
No related branches found
No related tags found
No related merge requests found
Pipeline #333340 failed
......@@ -56,27 +56,58 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
$link = $this->createMock(Link::class);
$link->method('toString')->willReturn(static::getGeneratedLink($name));
// 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;
});
// 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;
}
};
$created[$name] = $term;
}
......@@ -84,7 +115,7 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
$terms[] = $created[$name];
}
// Traverse the lineage from the end to set parents using the setter method.
// Traverse the lineage from the end to set parents.
$reverse = \array_reverse($lineage);
foreach ($reverse as $name) {
$parent_item = $this->createMock(EntityReferenceFieldItemListInterface::class);
......
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