Created
July 10, 2013 08:57
-
-
Save ChubV/5964630 to your computer and use it in GitHub Desktop.
Twig extension test case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ChubProduction\Bundle\XXXBundle\Tests; | |
/** | |
* TwigExtensionTestCase | |
* | |
* @author Vladimir Chub <[email protected]> | |
*/ | |
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