class 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

Expanded class hierarchy of FakeTemplateWrapper

File

core/modules/help_topics/tests/src/Unit/HelpTopicTwigTest.php, line 112

Namespace

Drupal\Tests\help_topics\Unit
View 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;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.