Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ChubV
Created July 10, 2013 08:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChubV/5964630 to your computer and use it in GitHub Desktop.
Save ChubV/5964630 to your computer and use it in GitHub Desktop.
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