Skip to content
Snippets Groups Projects
Commit b0855930 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 751c892f
No related branches found
No related tags found
No related merge requests found
Pipeline #333456 failed
......@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Drupal\Tests\cshs\Unit;
use PHPUnit\Framework\MockObject\MockObject;
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
use Drupal\Core\GeneratedLink;
use Drupal\Core\Language\LanguageInterface;
......@@ -57,23 +56,10 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
$link = $this->createMock(Link::class);
$link->method('toString')->willReturn(static::getGeneratedLink($name));
$term = $this->getMockBuilder(MockTerm::class)
->disableOriginalConstructor()
->onlyMethods(['id', 'label', 'toLink', 'getDescription', 'setDescription'])
->getMock();
$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);
// Explicitly add the 'parent' property to the mock.
$term->parent = NULL;
// Use the custom MockTerm class.
$term = new MockTerm(\random_int(1, 10000), $name, $link);
$created[$name] = $term;
}
$terms[] = $created[$name];
}
......@@ -82,7 +68,6 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
foreach ($reverse as $name) {
$parent_item = $this->createMock(EntityReferenceFieldItemListInterface::class);
$parent_item->target_id = ($parent = \next($reverse)) ? $created[$parent]->id() : NULL;
// Ensure parent is set.
$created[$name]->parent = $parent_item;
}
......@@ -320,14 +305,114 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
/**
*
*/
class MockTerm extends MockObject implements TermInterface {
class MockTerm implements TermInterface {
public $parent;
private $id;
private $label;
private $link;
/**
*
*/
public function __construct() {
public function __construct($id, $label, Link $link) {
$this->id = $id;
$this->label = $label;
$this->link = $link;
// Explicitly define the parent property.
$this->parent = NULL;
}
/**
*
*/
public function id() {
return $this->id;
}
/**
*
*/
public function label() {
return $this->label;
}
/**
*
*/
public function toLink($text = NULL, $rel = 'canonical', array $options = []) {
return $this->link;
}
/**
*
*/
public function getDescription() {}
/**
*
*/
public function setDescription($description) {}
/**
*
*/
public function getFormat() {}
/**
*
*/
public function setFormat($format) {}
/**
*
*/
public function getName() {
return $this->label;
}
/**
*
*/
public function setName($name) {
$this->label = $name;
}
/**
*
*/
public function getParentIds() {
return [];
}
/**
*
*/
public function setParentIds(array $parent_ids) {}
/**
*
*/
public function getParents() {
return [];
}
/**
*
*/
public function getChildren() {
return [];
}
/**
*
*/
public function getVocabularyId() {
return 'default';
}
/**
*
*/
public function setVocabularyId($vid) {}
}
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