Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Twig extension test case
<?php
namespace ChubProduction\Bundle\XXXBundle\Tests;
/**
* TwigExtensionTestCase
*
* @author Vladimir Chub <v@chub.com.ua>
*/
trait TwigExtensionTestCase
{
/**
* @var \Twig_Environment $twig
*/
private $twig;
/**
* @return \Twig_ExtensionInterface[] Extensions to register
*/
abstract protected function getExtensions();
public function setUpTwigExtension()
{
$this->twig = new \Twig_Environment(new \Twig_Loader_String());
$this->twig->setExtensions($this->getExtensions());
}
/**
* @param string $string
* @param mixed $context
*
* @return string
*/
public function render($string, $context)
{
return $this->twig->render($string, $context);
}
/**
* @return \Twig_Environment
*/
public function getTwig()
{
return $this->twig;
}
/**
* @param string $expected
* @param string $string
* @param array $context
* @param string $message
*/
protected function assertTwigEquals($expected, $string, $context, $message = '')
{
$actual = $this->render($string, $context);
$this->assertEquals($expected, $actual, $message);
}
/**
* @param string $expected
* @param string $string
* @param array $context
* @param string $message
*/
protected function assertTwigContains($expected, $string, $context, $message = '')
{
$actual = $this->render($string, $context);
$this->assertContains($expected, $actual, $message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.