From: Fabien Potencier Date: Tue, 24 Jan 2012 12:03:09 +0000 (+0100) Subject: added the possibility to skip some tests depending on the PHP version X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=0f9d7ffb4cbb92bbb74d35f2f959999b8f30fb20;p=web%2Fkonrad%2Ftwig.git added the possibility to skip some tests depending on the PHP version --- diff --git a/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test b/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test new file mode 100644 index 0000000..f260a09 --- /dev/null +++ b/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test @@ -0,0 +1,16 @@ +--TEST-- +"date" filter (interval support as of PHP 5.3) +--PHP-- +5.3.0 +--TEMPLATE-- +{{ date2|date }} +{{ date2|date('%d days') }} +--DATA-- +date_default_timezone_set('UTC'); +$twig->getExtension('core')->setDateFormat('Y-m-d', '%d days %h hours'); +return array( + 'date2' => new DateInterval('P2D'), +) +--EXPECT-- +2 days 0 hours +2 days diff --git a/test/Twig/Tests/Fixtures/filters/date_interval.test b/test/Twig/Tests/Fixtures/filters/date_interval.test new file mode 100644 index 0000000..1beaa10 --- /dev/null +++ b/test/Twig/Tests/Fixtures/filters/date_interval.test @@ -0,0 +1,16 @@ +--TEST-- +"date" filter (interval support as of PHP 5.3) +--PHP-- +5.3.0 +--TEMPLATE-- +{{ date6|date }} +{{ date6|date('%d days %h hours') }} +--DATA-- +date_default_timezone_set('UTC'); +return array( + 'date5' => -86410, + 'date6' => new DateInterval('P2D'), +) +--EXPECT-- +2 days +2 days 0 hours diff --git a/test/Twig/Tests/integrationTest.php b/test/Twig/Tests/integrationTest.php index 8f1d370..54775f0 100644 --- a/test/Twig/Tests/integrationTest.php +++ b/test/Twig/Tests/integrationTest.php @@ -23,21 +23,24 @@ class Twig_Tests_IntegrationTest extends PHPUnit_Framework_TestCase $test = file_get_contents($file->getRealpath()); - if (preg_match('/--TEST--\s*(.*?)\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*))+)\s*--EXCEPTION--\s*(.*)/s', $test, $match)) { + if (preg_match('/ + --TEST--\s*(.*?)\s*(?:--PHP--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*))+)\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) { $message = $match[1]; - $exception = $match[3]; - $templates = $this->parseTemplates($match[2]); + $php = $match[2]; + $templates = $this->parseTemplates($match[3]); + $exception = $match[4]; $outputs = array(); - } elseif (preg_match('/--TEST--\s*(.*?)\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) { + } elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--PHP--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) { $message = $match[1]; + $php = $match[2]; + $templates = $this->parseTemplates($match[3]); $exception = false; - $templates = $this->parseTemplates($match[2]); preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER); } else { throw new InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file))); } - $tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $templates, $exception, $outputs); + $tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $php, $templates, $exception, $outputs); } return $tests; @@ -46,8 +49,12 @@ class Twig_Tests_IntegrationTest extends PHPUnit_Framework_TestCase /** * @dataProvider getTests */ - public function testIntegration($file, $message, $templates, $exception, $outputs) + public function testIntegration($file, $message, $php, $templates, $exception, $outputs) { + if ($php && version_compare(phpversion(), $php, "<")) { + $this->markTestSkipped('Need PHP >= '.$php); + } + $loader = new Twig_Loader_Array($templates); foreach ($outputs as $match) {