diff --git a/lib/Twig/Test/IntegrationTestCase.php b/lib/Twig/Test/IntegrationTestCase.php index 96892a422..1ec575ee7 100644 --- a/lib/Twig/Test/IntegrationTestCase.php +++ b/lib/Twig/Test/IntegrationTestCase.php @@ -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) { diff --git a/test/Twig/Tests/LegacyIntegrationTest.php b/test/Twig/Tests/LegacyIntegrationTest.php index 02ec3cb29..055a61707 100644 --- a/test/Twig/Tests/LegacyIntegrationTest.php +++ b/test/Twig/Tests/LegacyIntegrationTest.php @@ -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