mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
More flexible integration test
This commit is contained in:
@@ -17,9 +17,43 @@
|
||||
*/
|
||||
abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
abstract protected function getExtensions();
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getFixturesDir();
|
||||
|
||||
/**
|
||||
* @return Twig_ExtensionInterface[]
|
||||
*/
|
||||
protected function getExtensions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter[]
|
||||
*/
|
||||
protected function getTwigFilters()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction[]
|
||||
*/
|
||||
protected function getTwigFunctions()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleTest[]
|
||||
*/
|
||||
protected function getTwigTests()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTests
|
||||
*/
|
||||
@@ -34,7 +68,7 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs)
|
||||
{
|
||||
$this->testIntegration($file, $message, $condition, $templates, $exception, $outputs);
|
||||
$this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs);
|
||||
}
|
||||
|
||||
public function getTests($name, $legacyTests = false)
|
||||
@@ -72,7 +106,7 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
|
||||
$tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs);
|
||||
}
|
||||
|
||||
if (!$tests) {
|
||||
if ($legacyTests && empty($tests)) {
|
||||
// add a dummy test to avoid a PHPUnit message
|
||||
return array(array('not', '-', '', array(), '', array()));
|
||||
}
|
||||
@@ -107,6 +141,18 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
|
||||
$twig->addExtension($extension);
|
||||
}
|
||||
|
||||
foreach ($this->getTwigFilters() as $filter) {
|
||||
$twig->addFilter($filter);
|
||||
}
|
||||
|
||||
foreach ($this->getTwigTests() as $test) {
|
||||
$twig->addTest($test);
|
||||
}
|
||||
|
||||
foreach ($this->getTwigFunctions() as $function) {
|
||||
$twig->addFunction($function);
|
||||
}
|
||||
|
||||
// avoid using the same PHP class name for different cases
|
||||
// only for PHP 5.2+
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
@@ -119,7 +165,7 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
|
||||
$template = $twig->loadTemplate('index.twig');
|
||||
} catch (Exception $e) {
|
||||
if (false !== $exception) {
|
||||
$this->assertEquals(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage())));
|
||||
$this->assertSame(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage())));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -137,7 +183,7 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
|
||||
$output = trim($template->render(eval($match[1].';')), "\n ");
|
||||
} catch (Exception $e) {
|
||||
if (false !== $exception) {
|
||||
$this->assertEquals(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage())));
|
||||
$this->assertSame(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage())));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -158,7 +204,7 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
|
||||
|
||||
$expected = trim($match[3], "\n ");
|
||||
|
||||
if ($expected != $output) {
|
||||
if ($expected !== $output) {
|
||||
printf("Compiled templates that failed on case %d:\n", $i + 1);
|
||||
|
||||
foreach (array_keys($templates) as $name) {
|
||||
|
||||
@@ -22,6 +22,15 @@ class Twig_Tests_LegacyIntegrationTest extends Twig_Test_IntegrationTestCase
|
||||
{
|
||||
return dirname(__FILE__).'/LegacyFixtures/';
|
||||
}
|
||||
|
||||
public function getTests($name, $legacyTests = false)
|
||||
{
|
||||
if (!$legacyTests) {
|
||||
return array(array('not', '-', '', array(), '', array()));
|
||||
}
|
||||
|
||||
return parent::getTests($name, true);
|
||||
}
|
||||
}
|
||||
|
||||
class LegacyTwigTestExtension extends Twig_Extension
|
||||
|
||||
Reference in New Issue
Block a user