Skip to content
Snippets Groups Projects
Commit 96a3a2a6 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 20dbe97e
No related branches found
No related tags found
No related merge requests found
Pipeline #332734 failed
......@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Drupal\Tests\cshs\Unit;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Link;
......@@ -111,317 +110,35 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
* The stubbed term object.
*/
protected function createMockTerm(int $id, string $label, Link $link, $parent = NULL): TermInterface {
return new class($id, $label, $link, $parent) implements TermInterface, \IteratorAggregate {
private $id;
private $label;
private $link;
public $parent;
/**
*
*/
public function __construct($id, $label, $link, $parent) {
$this->id = $id;
$this->label = $label;
$this->link = $link;
$this->parent = $parent;
}
/**
* Required methods from TermInterface and EntityInterface.
*/
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 getVocabularyId() {
return 'default';
}
/**
*
*/
public function setVocabularyId($vid) {}
/**
*
*/
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 getWeight() {
return 0;
}
/**
*
*/
public function setWeight($weight) {}
/**
*
*/
public function getParentIds() {
return [];
}
/**
*
*/
public function setParentIds(array $parent_ids) {}
/**
*
*/
public function getParents() {
return [];
}
/**
*
*/
public function getChildren() {
return [];
}
/**
* Implement the getIterator() method for IteratorAggregate.
*/
public function getIterator() {
return new \ArrayIterator([]);
}
/**
* Methods required by EntityPublishedInterface.
*/
public function isPublished() {
return TRUE;
}
/**
*
*/
public function setPublished() {}
/**
* Methods required by EntityInterface.
*/
public function bundle() {}
/**
*
*/
public function getEntityTypeId() {
return 'taxonomy_term';
}
/**
*
*/
public function uuid() {
return 'mock-uuid';
}
/**
*
*/
public function save() {}
/**
*
*/
public function delete() {}
/**
*
*/
public function isNew() {
return FALSE;
}
/**
*
*/
public function enforceIsNew($value = TRUE) {}
/**
*
*/
public function labelCallback() {}
/**
*
*/
public function toUrl($rel = 'canonical', array $options = []) {}
/**
*
*/
public function createDuplicate() {}
/**
*
*/
public function getCacheTagsToInvalidate() {
return [];
}
/**
*
*/
public function hasLinkTemplate($key) {
return FALSE;
}
/**
*
*/
public function toLinkTemplate($key, $text = NULL, array $options = []) {
return $this->link;
}
/**
* Methods required by FieldableEntityInterface.
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {}
/**
*
*/
public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {}
/**
*
*/
public function hasField($field_name) {
return FALSE;
}
/**
*
*/
public function get($field_name) {}
/**
*
*/
public function set($field_name, $value, $notify = TRUE) {
// Implement your logic here if necessary.
}
/**
*
*/
public function getFields($include_computed = TRUE) {
return [];
}
/**
*
*/
public function getFieldDefinitions() {
return [];
}
/**
*
*/
public function getFieldName($field_name) {
return $field_name;
}
/**
*
*/
public function getTranslation($langcode) {
return $this;
}
/**
*
*/
public function hasTranslation($langcode) {
return FALSE;
}
/**
*
*/
public function getTranslationLanguages($include_default = TRUE) {
return [];
}
/**
*
*/
public function addTranslation($langcode, array $values = []) {}
/**
*
*/
public function removeTranslation($langcode) {}
/**
*
*/
public function isDefaultTranslation() {
return TRUE;
}
$term_mock = $this->getMockBuilder(TermInterface::class)
->disableOriginalConstructor()
->onlyMethods([
'id',
'label',
'toLink',
'set',
'getFields',
'getFieldDefinition',
'getTranslatableFields',
'toArray',
])
->getMock();
/**
*
*/
public function setDefaultTranslation($is_default_translation) {}
$term_mock->method('id')->willReturn($id);
$term_mock->method('label')->willReturn($label);
$term_mock->method('toLink')->willReturn($link);
$term_mock->method('set')->willReturnSelf();
$term_mock->method('getFields')->willReturn([]);
$term_mock->method('getFieldDefinition')->willReturn(NULL);
$term_mock->method('getTranslatableFields')->willReturn([]);
$term_mock->method('toArray')->willReturn([]);
// Add parent if necessary.
if ($parent !== NULL) {
$term_mock->parent = $parent;
}
};
return $term_mock;
}
/**
......
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