21
21
use Twig \Node \Expression \ConditionalExpression ;
22
22
use Twig \Node \Expression \ConstantExpression ;
23
23
use Twig \Node \Expression \NameExpression ;
24
+ use Twig \Node \Expression \Ternary \ConditionalTernary ;
24
25
use Twig \Node \Expression \Variable \ContextVariable ;
25
26
use Twig \Node \Node ;
26
27
use Twig \Node \Nodes ;
@@ -275,32 +276,32 @@ public function testCompileLabelWithLabelAndAttributes()
275
276
276
277
public function testCompileLabelWithLabelThatEvaluatesToNull ()
277
278
{
279
+ if (class_exists (ConditionalTernary::class)) {
280
+ $ conditional = new ConditionalTernary (
281
+ // if
282
+ new ConstantExpression (true , 0 ),
283
+ // then
284
+ new ConstantExpression (null , 0 ),
285
+ // else
286
+ new ConstantExpression (null , 0 ),
287
+ 0
288
+ );
289
+ } else {
290
+ $ conditional = new ConditionalExpression (
291
+ // if
292
+ new ConstantExpression (true , 0 ),
293
+ // then
294
+ new ConstantExpression (null , 0 ),
295
+ // else
296
+ new ConstantExpression (null , 0 ),
297
+ 0
298
+ );
299
+ }
300
+
278
301
if (class_exists (Nodes::class)) {
279
- $ arguments = new Nodes ([
280
- new ContextVariable ('form ' , 0 ),
281
- new ConditionalExpression (
282
- // if
283
- new ConstantExpression (true , 0 ),
284
- // then
285
- new ConstantExpression (null , 0 ),
286
- // else
287
- new ConstantExpression (null , 0 ),
288
- 0
289
- ),
290
- ]);
302
+ $ arguments = new Nodes ([new ContextVariable ('form ' , 0 ), $ conditional ]);
291
303
} else {
292
- $ arguments = new Node ([
293
- new NameExpression ('form ' , 0 ),
294
- new ConditionalExpression (
295
- // if
296
- new ConstantExpression (true , 0 ),
297
- // then
298
- new ConstantExpression (null , 0 ),
299
- // else
300
- new ConstantExpression (null , 0 ),
301
- 0
302
- ),
303
- ]);
304
+ $ arguments = new Node ([new NameExpression ('form ' , 0 ), $ conditional ]);
304
305
}
305
306
306
307
$ node = new SearchAndRenderBlockNode (new TwigFunction ('form_label ' ), $ arguments , 0 );
@@ -322,18 +323,32 @@ public function testCompileLabelWithLabelThatEvaluatesToNull()
322
323
323
324
public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes ()
324
325
{
326
+ if (class_exists (ConditionalTernary::class)) {
327
+ $ conditional = new ConditionalTernary (
328
+ // if
329
+ new ConstantExpression (true , 0 ),
330
+ // then
331
+ new ConstantExpression (null , 0 ),
332
+ // else
333
+ new ConstantExpression (null , 0 ),
334
+ 0
335
+ );
336
+ } else {
337
+ $ conditional = new ConditionalExpression (
338
+ // if
339
+ new ConstantExpression (true , 0 ),
340
+ // then
341
+ new ConstantExpression (null , 0 ),
342
+ // else
343
+ new ConstantExpression (null , 0 ),
344
+ 0
345
+ );
346
+ }
347
+
325
348
if (class_exists (Nodes::class)) {
326
349
$ arguments = new Nodes ([
327
350
new ContextVariable ('form ' , 0 ),
328
- new ConditionalExpression (
329
- // if
330
- new ConstantExpression (true , 0 ),
331
- // then
332
- new ConstantExpression (null , 0 ),
333
- // else
334
- new ConstantExpression (null , 0 ),
335
- 0
336
- ),
351
+ $ conditional ,
337
352
new ArrayExpression ([
338
353
new ConstantExpression ('foo ' , 0 ),
339
354
new ConstantExpression ('bar ' , 0 ),
@@ -344,12 +359,7 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
344
359
} else {
345
360
$ arguments = new Node ([
346
361
new NameExpression ('form ' , 0 ),
347
- new ConditionalExpression (
348
- new ConstantExpression (true , 0 ),
349
- new ConstantExpression (null , 0 ),
350
- new ConstantExpression (null , 0 ),
351
- 0
352
- ),
362
+ $ conditional ,
353
363
new ArrayExpression ([
354
364
new ConstantExpression ('foo ' , 0 ),
355
365
new ConstantExpression ('bar ' , 0 ),
0 commit comments