diff --git a/.travis.yml b/.travis.yml index b71f94479..044083721 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CHANGELOG b/CHANGELOG index 64d19726e..e0b2d0dfd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/doc/advanced.rst b/doc/advanced.rst index 1fbefa258..51498489e 100644 --- a/doc/advanced.rst +++ b/doc/advanced.rst @@ -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 ---- diff --git a/lib/Twig/Node/Expression/Test.php b/lib/Twig/Node/Expression/Test.php index 7a1aed8ed..3ffad6594 100644 --- a/lib/Twig/Node/Expression/Test.php +++ b/lib/Twig/Node/Expression/Test.php @@ -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()); diff --git a/test/Twig/Tests/IntegrationTest.php b/test/Twig/Tests/IntegrationTest.php index 027180f12..bfe5b6721 100644 --- a/test/Twig/Tests/IntegrationTest.php +++ b/test/Twig/Tests/IntegrationTest.php @@ -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);