File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -494,11 +494,28 @@ public function getTest(int $line): TwigTest
494494 // try 2-words tests
495495 $ name = $ name .' ' .$ this ->getCurrentToken ()->getValue ();
496496
497- if ($ test = $ this ->env ->getTest ($ name )) {
497+ try {
498+ $ test = $ this ->env ->getTest ($ name );
499+ } catch (SyntaxError $ e ) {
500+ if (!$ this ->shouldIgnoreUnknownTwigCallables ()) {
501+ throw $ e ;
502+ }
503+
504+ $ test = null ;
505+ }
506+ if ($ test ) {
498507 $ this ->stream ->next ();
499508 }
500509 } else {
501- $ test = $ this ->env ->getTest ($ name );
510+ try {
511+ $ test = $ this ->env ->getTest ($ name );
512+ } catch (SyntaxError $ e ) {
513+ if (!$ this ->shouldIgnoreUnknownTwigCallables ()) {
514+ throw $ e ;
515+ }
516+
517+ $ test = null ;
518+ }
502519 }
503520
504521 if (!$ test ) {
Original file line number Diff line number Diff line change @@ -101,6 +101,14 @@ protected function getUndefinedFunctionCallbacks(): array
101101 return [];
102102 }
103103
104+ /**
105+ * @return array<callable(string): (TwigTest|false)>
106+ */
107+ protected function getUndefinedTestCallbacks (): array
108+ {
109+ return [];
110+ }
111+
104112 /**
105113 * @return array<callable(string): (TokenParserInterface|false)>
106114 */
Original file line number Diff line number Diff line change 1414{% else -%}
1515 The throwing_undefined_function function doesn't exist
1616{% endguard %}
17+
18+ {% guard function throwing_undefined_test -%}
19+ NEVER
20+ {{ 'a' is throwing_undefined_test('b') }}
21+ {% else -%}
22+ The throwing_undefined_test function doesn't exist
23+ {% endguard %}
1724--DATA--
1825return []
1926--EXPECT--
2027The throwing_undefined_filter filter doesn't exist
2128
2229The throwing_undefined_function function doesn't exist
30+
31+ The throwing_undefined_test function doesn't exist
Original file line number Diff line number Diff line change @@ -72,6 +72,19 @@ static function (string $name) {
7272 ];
7373 }
7474
75+ protected function getUndefinedTestCallbacks (): array
76+ {
77+ return [
78+ static function (string $ name ) {
79+ if ('throwing_undefined_test ' === $ name ) {
80+ throw new SyntaxError ('This test is undefined in the tests. ' );
81+ }
82+
83+ return false ;
84+ },
85+ ];
86+ }
87+
7588 protected function getUndefinedTokenParserCallbacks (): array
7689 {
7790 return [
You can’t perform that action at this time.
0 commit comments