Skip to content
Snippets Groups Projects
Commit 179b1b5c 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 5e5a4c73
No related branches found
No related tags found
No related merge requests found
Pipeline #332404 failed
......@@ -39,35 +39,25 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
->onlyMethods(['getSetting', 'getTermStorage', 'getEntitiesToView', 'getTranslationFromContext'])
->getMock();
$mock
->method('getSetting')
->willReturnCallback(fn($key) => $settings[$key] ?? NULL);
$mock->method('getSetting')->willReturnCallback(fn($key) => $settings[$key] ?? NULL);
$terms = $this->createTerms($tree);
$terms_to_view = array_map(static fn (array $lineage): TermInterface => end($lineage), $terms);
$mock->expects($this->once())
->method('getEntitiesToView')
->willReturn($terms_to_view);
$mock->expects($this->once())->method('getEntitiesToView')->willReturn($terms_to_view);
$term_storage = $this->createMock(TermStorageInterface::class);
foreach ($terms_to_view as $index => $term) {
$term_storage
->expects($this->exactly(count($terms_to_view)))
$term_storage->expects($this->exactly(count($terms_to_view)))
->method('loadAllParents')
->with($term->id())
->willReturn(array_reverse($terms[$index]));
}
$mock->expects($this->exactly(count($terms_to_view)))
->method('getTermStorage')
->willReturn($term_storage);
$mock->expects($this->exactly(count($terms_to_view)))->method('getTermStorage')->willReturn($term_storage);
$mock
->method('getTranslationFromContext')
->willReturnArgument(0);
$mock->method('getTranslationFromContext')->willReturnArgument(0);
$elements = $mock->viewElements(
$this->createMock(EntityReferenceFieldItemListInterface::class),
......@@ -115,11 +105,11 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
$terms[] = $created[$name];
}
// Set parents for the terms.
// Set up parent hierarchy without dynamic properties.
foreach (array_reverse($lineage) as $name) {
$parent_item = $this->createMock(EntityReferenceFieldItemListInterface::class);
$parent_item->target_id = ($parent = next($lineage)) ? $created[$parent]->id() : NULL;
$created[$name]->parent = $parent_item;
$created[$name]->expects($this->any())->method('getParent')->willReturn($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