class FakeTemplateWrapper in Drupal 9
Same name and namespace in other branches
- 8 core/modules/help_topics/tests/src/Unit/HelpTopicTwigTest.php \Drupal\Tests\help_topics\Unit\FakeTemplateWrapper
Defines a fake template class to mock \Twig\TemplateWrapper.
We cannot use getMockBuilder() for this, because the Twig TemplateWrapper class is declared "final" and cannot be mocked.
Hierarchy
- class \Drupal\Tests\help_topics\Unit\FakeTemplateWrapper
Expanded class hierarchy of FakeTemplateWrapper
File
- core/
modules/ help_topics/ tests/ src/ Unit/ HelpTopicTwigTest.php, line 112
Namespace
Drupal\Tests\help_topics\UnitView source
class FakeTemplateWrapper {
/**
* Body text to return from the render() method.
*
* @var string
*/
protected $body;
/**
* Constructor.
*
* @param string $body
* Body text to return from the render() method.
*/
public function __construct($body) {
$this->body = $body;
}
/**
* Mocks the \Twig\TemplateWrapper render() method.
*
* @param array $context
* (optional) Render context.
*/
public function render(array $context = []) {
return $this->body;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FakeTemplateWrapper:: |
protected | property | Body text to return from the render() method. | |
FakeTemplateWrapper:: |
public | function | Mocks the \Twig\TemplateWrapper render() method. | |
FakeTemplateWrapper:: |
public | function | Constructor. |