From: Fabien Potencier Date: Mon, 6 Feb 2012 15:21:45 +0000 (+0100) Subject: added more safeguards in unit tests to support different configuraitons X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=5dd0aaec16c21ba03c247cbb9672d5a91c544af0;p=web%2Fkonrad%2Ftwig.git added more safeguards in unit tests to support different configuraitons --- diff --git a/test/Twig/Tests/Extension/CoreTest.php b/test/Twig/Tests/Extension/CoreTest.php index ac27dff..89a7750 100644 --- a/test/Twig/Tests/Extension/CoreTest.php +++ b/test/Twig/Tests/Extension/CoreTest.php @@ -83,6 +83,10 @@ class Twig_Tests_Extension_CoreTest extends PHPUnit_Framework_TestCase public function testRandomFunctionOnNonUTF8String() { + if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) { + $this->markTestSkipped('needs iconv or mbstring'); + } + $twig = new Twig_Environment(); $twig->setCharset('ISO-8859-1'); @@ -95,6 +99,10 @@ class Twig_Tests_Extension_CoreTest extends PHPUnit_Framework_TestCase public function testReverseFilterOnNonUTF8String() { + if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) { + $this->markTestSkipped('needs iconv or mbstring'); + } + $twig = new Twig_Environment(); $twig->setCharset('ISO-8859-1'); diff --git a/test/Twig/Tests/Fixtures/filters/convert_encoding.test b/test/Twig/Tests/Fixtures/filters/convert_encoding.test index b386d4e..380b04b 100644 --- a/test/Twig/Tests/Fixtures/filters/convert_encoding.test +++ b/test/Twig/Tests/Fixtures/filters/convert_encoding.test @@ -1,5 +1,7 @@ --TEST-- "convert_encoding" filter +--CONDITION-- +function_exists('iconv') || function_exists('mb_convert_encoding') --TEMPLATE-- {{ "愛していますか?"|convert_encoding('ISO-2022-JP', 'UTF-8')|convert_encoding('UTF-8', 'ISO-2022-JP') }} --DATA-- diff --git a/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test b/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test index f260a09..e6d3707 100644 --- a/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test +++ b/test/Twig/Tests/Fixtures/filters/date_default_format_interval.test @@ -1,7 +1,7 @@ --TEST-- "date" filter (interval support as of PHP 5.3) ---PHP-- -5.3.0 +--CONDITION-- +version_compare(phpversion(), '5.3.0', '>=') --TEMPLATE-- {{ date2|date }} {{ date2|date('%d days') }} diff --git a/test/Twig/Tests/Fixtures/filters/date_interval.test b/test/Twig/Tests/Fixtures/filters/date_interval.test index 1beaa10..2d5adc1 100644 --- a/test/Twig/Tests/Fixtures/filters/date_interval.test +++ b/test/Twig/Tests/Fixtures/filters/date_interval.test @@ -1,7 +1,7 @@ --TEST-- "date" filter (interval support as of PHP 5.3) ---PHP-- -5.3.0 +--CONDITION-- +version_compare(phpversion(), '5.3.0', '>=') --TEMPLATE-- {{ date6|date }} {{ date6|date('%d days %h hours') }} diff --git a/test/Twig/Tests/Fixtures/filters/length.test b/test/Twig/Tests/Fixtures/filters/length.test index 6de51e0..3347474 100644 --- a/test/Twig/Tests/Fixtures/filters/length.test +++ b/test/Twig/Tests/Fixtures/filters/length.test @@ -6,7 +6,7 @@ {{ number|length }} {{ markup|length }} --DATA-- -return array('array' => array(1, 4), 'string' => 'foo', 'number' => 1000, 'markup' => new Twig_Markup('été', 'UTF-8')) +return array('array' => array(1, 4), 'string' => 'foo', 'number' => 1000, 'markup' => new Twig_Markup('foo', 'UTF-8')) --EXPECT-- 2 3 diff --git a/test/Twig/Tests/integrationTest.php b/test/Twig/Tests/integrationTest.php index 54775f0..2045097 100644 --- a/test/Twig/Tests/integrationTest.php +++ b/test/Twig/Tests/integrationTest.php @@ -24,15 +24,15 @@ class Twig_Tests_IntegrationTest extends PHPUnit_Framework_TestCase $test = file_get_contents($file->getRealpath()); if (preg_match('/ - --TEST--\s*(.*?)\s*(?:--PHP--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*))+)\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) { + --TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*))+)\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) { $message = $match[1]; - $php = $match[2]; + $condition = $match[2]; $templates = $this->parseTemplates($match[3]); $exception = $match[4]; $outputs = array(); - } elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--PHP--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) { + } elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) { $message = $match[1]; - $php = $match[2]; + $condition = $match[2]; $templates = $this->parseTemplates($match[3]); $exception = false; preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER); @@ -40,7 +40,7 @@ class Twig_Tests_IntegrationTest extends PHPUnit_Framework_TestCase throw new InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file))); } - $tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $php, $templates, $exception, $outputs); + $tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $templates, $exception, $outputs); } return $tests; @@ -49,10 +49,13 @@ class Twig_Tests_IntegrationTest extends PHPUnit_Framework_TestCase /** * @dataProvider getTests */ - public function testIntegration($file, $message, $php, $templates, $exception, $outputs) + public function testIntegration($file, $message, $condition, $templates, $exception, $outputs) { - if ($php && version_compare(phpversion(), $php, "<")) { - $this->markTestSkipped('Need PHP >= '.$php); + if ($condition) { + eval('$ret = '.$condition.';'); + if (!$ret) { + $this->markTestSkipped($condition); + } } $loader = new Twig_Loader_Array($templates);