Skip to content
Snippets Groups Projects
Commit bcaef31c 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 2cf3c534
No related branches found
No related tags found
No related merge requests found
Pipeline #332615 failed
<?xml version="1.0"?>
<!-- See https://github.com/pfrenssen/coder#store-settings-in-a-phpcsxmldist-file -->
<ruleset name="Drupal">
<description>The coding standard for our project.</description>
<rule ref="Drupal"/>
<!-- Check all files in the current directory and below. -->
<file>.</file>
<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,md,yml"/>
<!-- Change this value to 7 if you want to check Drupal 7 code. -->
<config name="drupal_core_version" value="11"/>
<!-- Show progression -->
<arg value="p"/>
<!-- Customizations -->
<rule ref="Drupal.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="130"/>
</properties>
</rule>
</ruleset>
......@@ -106,20 +106,115 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
* @param string|null $parent
* The parent term ID (if any).
*
* @return \Drupal\taxonomy\TermInterface|\PHPUnit\Framework\MockObject\MockObject
* The mocked term object.
* @return \Drupal\taxonomy\TermInterface
* The stubbed term object.
*/
protected function createMockTerm(int $id, string $label, Link $link, $parent = NULL): TermInterface {
$term = $this->createMock(TermInterface::class);
return new class($id, $label, $link, $parent) implements TermInterface {
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;
}
/**
*
*/
public function id() {
return $this->id;
}
/**
*
*/
public function label() {
return $this->label;
}
$term->method('id')->willReturn($id);
$term->method('label')->willReturn($label);
$term->method('toLink')->willReturn($link);
/**
*
*/
public function toLink($text = NULL, $rel = 'canonical', array $options = []) {
return $this->link;
}
// Define the parent property explicitly to avoid deprecation.
$term->parent = $parent;
/**
* Implement only the required methods for your test.
*/
public function getIterator() {
return new \ArrayIterator([]);
}
return $term;
/**
* Stub out any additional required methods to satisfy TermInterface.
*/
public function bundle() {}
/**
*
*/
public function getEntityTypeId() {}
/**
*
*/
public function uuid() {}
/**
*
*/
public function getDescription() {}
/**
*
*/
public function setDescription($description) {}
/**
*
*/
public function getFormat() {}
/**
*
*/
public function setFormat($format) {}
/**
*
*/
public function save() {}
/**
*
*/
public function delete() {}
/**
*
*/
public function isNew() {}
/**
*
*/
public function enforceIsNew($value = TRUE) {}
/**
*
*/
public function labelCallback() {}
};
}
/**
......@@ -142,18 +237,11 @@ class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
$link = $this->createMock(Link::class);
$link->method('toString')->willReturn(static::getGeneratedLink($name));
// Create a partial mock of TermInterface.
$term = $this->getMockBuilder(TermInterface::class)
->disableOriginalConstructor()
->onlyMethods(['id', 'label', 'toLink'])
->getMock();
// Mock the necessary methods.
$term->method('id')->willReturn($this->getFixedTermId($name));
$term->method('label')->willReturn($name);
$term->method('toLink')->willReturn($link);
// Use the custom stub class.
$term_id = $this->getFixedTermId($name);
$term = $this->createMockTerm($term_id, $name, $link);
// Store the term.
// Store the created term.
$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