fixed tests on PHP 5.2

This commit is contained in:
Fabien Potencier
2013-01-04 22:34:22 +01:00
parent e48b1f3bdf
commit 84504c3c39
6 changed files with 42 additions and 15 deletions
@@ -76,8 +76,10 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase
$tests[] = array($node, 'twig_reverse_filter($this->env, "abc", true)');
// filter as an anonymous function
$node = $this->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous');
$tests[] = array($node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), array("foo"))');
if (version_compare(phpversion(), '5.3.0', '>=')) {
$node = $this->createFilter(new Twig_Node_Expression_Constant('foo', 1), 'anonymous');
$tests[] = array($node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), array("foo"))');
}
return $tests;
}
@@ -122,9 +124,10 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase
protected function getEnvironment()
{
$env = parent::getEnvironment();
$env->addFilter(new Twig_SimpleFilter('anonymous', function () {}));
if (version_compare(phpversion(), '5.3.0', '>=')) {
return include 'PHP53/FilterTest.php';
}
return $env;
return parent::getEnvironment();
}
}
@@ -75,8 +75,10 @@ class Twig_Tests_Node_Expression_FunctionTest extends Twig_Test_NodeTestCase
$tests[] = array($node, 'twig_date_converter($this->env, 0, "America/Chicago")');
// function as an anonymous function
$node = $this->createFunction('anonymous', array(new Twig_Node_Expression_Constant('foo', 1)));
$tests[] = array($node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), array("foo"))');
if (version_compare(phpversion(), '5.3.0', '>=')) {
$node = $this->createFunction('anonymous', array(new Twig_Node_Expression_Constant('foo', 1)));
$tests[] = array($node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), array("foo"))');
}
return $tests;
}
@@ -88,9 +90,10 @@ class Twig_Tests_Node_Expression_FunctionTest extends Twig_Test_NodeTestCase
protected function getEnvironment()
{
$env = parent::getEnvironment();
$env->addFunction(new Twig_SimpleFunction('anonymous', function () {}));
if (version_compare(phpversion(), '5.3.0', '>=')) {
return include 'PHP53/FunctionTest.php';
}
return $env;
return parent::getEnvironment();
}
}
@@ -0,0 +1,6 @@
<?php
$env = new Twig_Environment();
$env->addFilter(new Twig_SimpleFilter('anonymous', function () {}));
return $env;
@@ -0,0 +1,6 @@
<?php
$env = new Twig_Environment();
$env->addFunction(new Twig_SimpleFunction('anonymous', function () {}));
return $env;
@@ -0,0 +1,6 @@
<?php
$env = new Twig_Environment();
$env->addTest(new Twig_SimpleTest('anonymous', function () {}));
return $env;
+8 -5
View File
@@ -44,8 +44,10 @@ class Twig_Tests_Node_Expression_TestTest extends Twig_Test_NodeTestCase
$tests[] = array($node, '(null === "foo")');
// test as an anonymous function
$node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', array(new Twig_Node_Expression_Constant('foo', 1)));
$tests[] = array($node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), array("foo", "foo"))');
if (version_compare(phpversion(), '5.3.0', '>=')) {
$node = $this->createTest(new Twig_Node_Expression_Constant('foo', 1), 'anonymous', array(new Twig_Node_Expression_Constant('foo', 1)));
$tests[] = array($node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), array("foo", "foo"))');
}
return $tests;
}
@@ -57,9 +59,10 @@ class Twig_Tests_Node_Expression_TestTest extends Twig_Test_NodeTestCase
protected function getEnvironment()
{
$env = parent::getEnvironment();
$env->addTest(new Twig_SimpleTest('anonymous', function () {}));
if (version_compare(phpversion(), '5.3.0', '>=')) {
return include 'PHP53/TestTest.php';
}
return $env;
return parent::getEnvironment();
}
}