mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 11:56:50 +00:00
Merge branch '1.x' into 2.x
* 1.x: Add support for dynamic tests
This commit is contained in:
+1
-1
@@ -24,7 +24,7 @@ install:
|
||||
|
||||
script: |
|
||||
if [[ $TRAVIS_PHP_VERSION = 7.* || $TRAVIS_PHP_VERSION = nightly ]]; then
|
||||
SYMFONY_PHPUNIT_VERSION=6.1 ./vendor/bin/simple-phpunit
|
||||
SYMFONY_PHPUNIT_VERSION=6.5 ./vendor/bin/simple-phpunit
|
||||
else
|
||||
./vendor/bin/simple-phpunit
|
||||
fi
|
||||
|
||||
@@ -120,8 +120,9 @@
|
||||
* improved the performance of the filesystem loader
|
||||
* removed features that were deprecated in 1.x
|
||||
|
||||
* 1.35.5 (2018-XX-XX)
|
||||
* 1.36.0 (2018-XX-XX)
|
||||
|
||||
* added support for dynamically named tests
|
||||
* fixed filesystem loader throwing an exception instead of returning false
|
||||
|
||||
* 1.35.4 (2018-07-13)
|
||||
|
||||
+5
-2
@@ -358,9 +358,12 @@ The ``node`` sub-node will contain an expression of ``my_value``. Node-based
|
||||
tests also have access to the ``arguments`` node. This node will contain the
|
||||
various other arguments that have been provided to your test.
|
||||
|
||||
.. versionadded:: 1.36
|
||||
Dynamic tests support was added in Twig 1.36.
|
||||
|
||||
If you want to pass a variable number of positional or named arguments to the
|
||||
test, set the ``is_variadic`` option to ``true``. Tests also support dynamic
|
||||
name feature as filters and functions.
|
||||
test, set the ``is_variadic`` option to ``true``. Tests support dynamic
|
||||
names (see dynamic filters and functions for the syntax).
|
||||
|
||||
Tags
|
||||
----
|
||||
|
||||
@@ -27,6 +27,7 @@ class Twig_Node_Expression_Test extends Twig_Node_Expression_Call
|
||||
|
||||
$this->setAttribute('name', $name);
|
||||
$this->setAttribute('type', 'test');
|
||||
$this->setAttribute('arguments', $test->getArguments());
|
||||
$this->setAttribute('callable', $test->getCallable());
|
||||
$this->setAttribute('is_variadic', $test->isVariadic());
|
||||
|
||||
|
||||
@@ -170,6 +170,7 @@ class TwigTestExtension extends Twig_Extension
|
||||
{
|
||||
return array(
|
||||
new Twig_Test('multi word', array($this, 'is_multi_word')),
|
||||
new Twig_Test('test_*', array($this, 'dynamic_test')),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -211,6 +212,11 @@ class TwigTestExtension extends Twig_Extension
|
||||
return $foo.'/'.$bar.'/'.$item;
|
||||
}
|
||||
|
||||
public function dynamic_test($element, $item)
|
||||
{
|
||||
return $element === $item;
|
||||
}
|
||||
|
||||
public function escape_something($value)
|
||||
{
|
||||
return strtoupper($value);
|
||||
|
||||
Reference in New Issue
Block a user