1313
1414use PHPUnit \Framework \TestCase ;
1515use Symfony \Bridge \Twig \Node \SearchAndRenderBlockNode ;
16+ use Twig \Attribute \FirstClassTwigCallableReady ;
1617use Twig \Compiler ;
1718use Twig \Environment ;
1819use Twig \Extension \CoreExtension ;
2223use Twig \Node \Expression \ConstantExpression ;
2324use Twig \Node \Expression \NameExpression ;
2425use Twig \Node \Node ;
26+ use Twig \TwigFunction ;
2527
2628class SearchAndRenderBlockNodeTest extends TestCase
2729{
@@ -31,7 +33,11 @@ public function testCompileWidget()
3133 new NameExpression ('form ' , 0 ),
3234 ]);
3335
34- $ node = new SearchAndRenderBlockNode ('form_widget ' , $ arguments , 0 );
36+ if (class_exists (FirstClassTwigCallableReady::class)) {
37+ $ node = new SearchAndRenderBlockNode (new TwigFunction ('form_widget ' ), $ arguments , 0 );
38+ } else {
39+ $ node = new SearchAndRenderBlockNode ('form_widget ' , $ arguments , 0 );
40+ }
3541
3642 $ compiler = new Compiler (new Environment ($ this ->createMock (LoaderInterface::class)));
3743
@@ -54,7 +60,11 @@ public function testCompileWidgetWithVariables()
5460 ], 0 ),
5561 ]);
5662
57- $ node = new SearchAndRenderBlockNode ('form_widget ' , $ arguments , 0 );
63+ if (class_exists (FirstClassTwigCallableReady::class)) {
64+ $ node = new SearchAndRenderBlockNode (new TwigFunction ('form_widget ' ), $ arguments , 0 );
65+ } else {
66+ $ node = new SearchAndRenderBlockNode ('form_widget ' , $ arguments , 0 );
67+ }
5868
5969 $ compiler = new Compiler (new Environment ($ this ->createMock (LoaderInterface::class)));
6070
@@ -74,7 +84,11 @@ public function testCompileLabelWithLabel()
7484 new ConstantExpression ('my label ' , 0 ),
7585 ]);
7686
77- $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
87+ if (class_exists (FirstClassTwigCallableReady::class)) {
88+ $ node = new SearchAndRenderBlockNode (new TwigFunction ('form_label ' ), $ arguments , 0 );
89+ } else {
90+ $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
91+ }
7892
7993 $ compiler = new Compiler (new Environment ($ this ->createMock (LoaderInterface::class)));
8094
@@ -94,7 +108,11 @@ public function testCompileLabelWithNullLabel()
94108 new ConstantExpression (null , 0 ),
95109 ]);
96110
97- $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
111+ if (class_exists (FirstClassTwigCallableReady::class)) {
112+ $ node = new SearchAndRenderBlockNode (new TwigFunction ('form_label ' ), $ arguments , 0 );
113+ } else {
114+ $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
115+ }
98116
99117 $ compiler = new Compiler (new Environment ($ this ->createMock (LoaderInterface::class)));
100118
@@ -116,7 +134,11 @@ public function testCompileLabelWithEmptyStringLabel()
116134 new ConstantExpression ('' , 0 ),
117135 ]);
118136
119- $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
137+ if (class_exists (FirstClassTwigCallableReady::class)) {
138+ $ node = new SearchAndRenderBlockNode (new TwigFunction ('form_label ' ), $ arguments , 0 );
139+ } else {
140+ $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
141+ }
120142
121143 $ compiler = new Compiler (new Environment ($ this ->createMock (LoaderInterface::class)));
122144
@@ -137,7 +159,11 @@ public function testCompileLabelWithDefaultLabel()
137159 new NameExpression ('form ' , 0 ),
138160 ]);
139161
140- $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
162+ if (class_exists (FirstClassTwigCallableReady::class)) {
163+ $ node = new SearchAndRenderBlockNode (new TwigFunction ('form_label ' ), $ arguments , 0 );
164+ } else {
165+ $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
166+ }
141167
142168 $ compiler = new Compiler (new Environment ($ this ->createMock (LoaderInterface::class)));
143169
@@ -161,7 +187,11 @@ public function testCompileLabelWithAttributes()
161187 ], 0 ),
162188 ]);
163189
164- $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
190+ if (class_exists (FirstClassTwigCallableReady::class)) {
191+ $ node = new SearchAndRenderBlockNode (new TwigFunction ('form_label ' ), $ arguments , 0 );
192+ } else {
193+ $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
194+ }
165195
166196 $ compiler = new Compiler (new Environment ($ this ->createMock (LoaderInterface::class)));
167197
@@ -190,7 +220,11 @@ public function testCompileLabelWithLabelAndAttributes()
190220 ], 0 ),
191221 ]);
192222
193- $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
223+ if (class_exists (FirstClassTwigCallableReady::class)) {
224+ $ node = new SearchAndRenderBlockNode (new TwigFunction ('form_label ' ), $ arguments , 0 );
225+ } else {
226+ $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
227+ }
194228
195229 $ compiler = new Compiler (new Environment ($ this ->createMock (LoaderInterface::class)));
196230
@@ -218,7 +252,11 @@ public function testCompileLabelWithLabelThatEvaluatesToNull()
218252 ),
219253 ]);
220254
221- $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
255+ if (class_exists (FirstClassTwigCallableReady::class)) {
256+ $ node = new SearchAndRenderBlockNode (new TwigFunction ('form_label ' ), $ arguments , 0 );
257+ } else {
258+ $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
259+ }
222260
223261 $ compiler = new Compiler (new Environment ($ this ->createMock (LoaderInterface::class)));
224262
@@ -256,7 +294,11 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
256294 ], 0 ),
257295 ]);
258296
259- $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
297+ if (class_exists (FirstClassTwigCallableReady::class)) {
298+ $ node = new SearchAndRenderBlockNode (new TwigFunction ('form_label ' ), $ arguments , 0 );
299+ } else {
300+ $ node = new SearchAndRenderBlockNode ('form_label ' , $ arguments , 0 );
301+ }
260302
261303 $ compiler = new Compiler (new Environment ($ this ->createMock (LoaderInterface::class)));
262304
0 commit comments