Skip to content
Snippets Groups Projects
Commit 97ab0247 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 166156e4
No related branches found
No related tags found
No related merge requests found
Pipeline #332608 failed
......@@ -59,11 +59,14 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
$parents = [];
while (isset($this->parentRelationships[$term_id])) {
$parent = $this->parentRelationships[$term_id];
if ($parent === NULL || !property_exists($parent, 'target_id')) {
// Ensure $parent is a valid object before accessing its properties.
if ($parent === NULL || !is_object($parent) || !method_exists($parent, 'id')) {
break;
}
$parents[] = $parent;
$term_id = $parent->target_id;
$term_id = $parent->id();
}
return array_reverse($parents);
});
......@@ -109,17 +112,26 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
protected function createMockTerm(int $id, string $label, Link $link, $parent = NULL): TermInterface {
$term = $this->createMock(TermInterface::class);
// Mock only the methods you need.
$term->method('id')->willReturn($id);
$term->method('label')->willReturn($label);
$term->method('toLink')->willReturn($link);
// Set the parent property dynamically if needed.
// Define the parent property explicitly to avoid deprecation.
$term->parent = $parent;
return $term;
}
/**
* Creates mock terms based on a hierarchy tree and assigns parent IDs.
*
* @param array $tree
* Array representing term hierarchy.
*
* @return array[]
* Array of mock term hierarchies.
*/
/**
* Creates mock terms based on a hierarchy tree and assigns parent IDs.
*
......@@ -140,12 +152,53 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
$link = $this->createMock(Link::class);
$link->method('toString')->willReturn(static::getGeneratedLink($name));
// Create a mock term using the `createMockTerm` method.
$term_id = $this->getFixedTermId($name);
$term = $this->createMockTerm($term_id, $name, $link);
// Store the created term.
$created[$name] = $term;
// Create an anonymous class implementing TermInterface.
$term = new class($this->getFixedTermId($name), $name, $link) implements TermInterface, \IteratorAggregate {
public int $target_id;
public string $label;
public Link $link;
public ?self $parent = NULL;
/**
*
*/
public function __construct($id, $label, $link) {
$this->target_id = $id;
$this->label = $label;
$this->link = $link;
}
/**
*
*/
public function id() {
return $this->target_id;
}
/**
*
*/
public function label() {
return $this->label;
}
/**
*
*/
public function toLink($text = NULL, $rel = 'canonical', array $options = []) {
return $this->link;
}
/**
*
*/
public function getIterator() {
return new \ArrayIterator($this);
}
};
$created[$name] = $term;
}
$terms[] = $created[$name];
}
......
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