假设我有以下方法
public function prepareEmail($dataModel)
{
return $this->container->get('templating')->render(
'MyBundle:Emails:email-document.html.twig',
[
'data' => $dataModel,
]
)
}
我想测试树枝模板中存在的非常复杂的逻辑。
在我的phpunit测试工具包中,我没有嘲笑TwigEngine
服务,因此我正在使用完全渲染的模板。
在测试中,我做这样的事情
public function testPrepareEmail()
{
$template = $this->manager->prepareEmail($testData);
static::assertContains('some part of template', $template);
}
一切看起来不错,但是我将以下字符串添加到了我的模板之一
{{ app.request.getSchemeAndHttpHost() }}
现在我出错了
Twig_Error_Runtime : Impossible to invoke a method ("getSchemeAndHttpHost") on a null variable.
这是非常合理的,问题是在我的情况下如何模拟Symfony Request
对象?