File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed
src/Symfony/Component/Config Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1
1
CHANGELOG
2
2
=========
3
3
4
+ 7.3
5
+ ---
6
+
7
+ * Add ` ExprBuilder::ifFalse() `
8
+
4
9
7.2
5
10
---
6
11
Original file line number Diff line number Diff line change @@ -67,6 +67,21 @@ public function ifTrue(?\Closure $closure = null): static
67
67
return $ this ;
68
68
}
69
69
70
+ /**
71
+ * Sets a closure to use as tests.
72
+ *
73
+ * The default one tests if the value is false.
74
+ *
75
+ * @return $this
76
+ */
77
+ public function ifFalse (?\Closure $ closure = null ): static
78
+ {
79
+ $ this ->ifPart = $ closure ?? static fn ($ v ) => false === $ v ;
80
+ $ this ->allowedTypes = self ::TYPE_ANY ;
81
+
82
+ return $ this ;
83
+ }
84
+
70
85
/**
71
86
* Tests if the value is a string.
72
87
*
Original file line number Diff line number Diff line change @@ -49,6 +49,27 @@ public function testIfTrueExpression()
49
49
$ this ->assertFinalizedValueIs ('value ' , $ test );
50
50
}
51
51
52
+ public function testIfFalseExpression ()
53
+ {
54
+ $ test = $ this ->getTestBuilder ()
55
+ ->ifFalse ()
56
+ ->then ($ this ->returnClosure ('new_value ' ))
57
+ ->end ();
58
+ $ this ->assertFinalizedValueIs ('new_value ' , $ test , ['key ' => false ]);
59
+
60
+ $ test = $ this ->getTestBuilder ()
61
+ ->ifFalse (fn () => true )
62
+ ->then ($ this ->returnClosure ('new_value ' ))
63
+ ->end ();
64
+ $ this ->assertFinalizedValueIs ('new_value ' , $ test );
65
+
66
+ $ test = $ this ->getTestBuilder ()
67
+ ->ifFalse (fn () => false )
68
+ ->then ($ this ->returnClosure ('new_value ' ))
69
+ ->end ();
70
+ $ this ->assertFinalizedValueIs ('value ' , $ test );
71
+ }
72
+
52
73
public function testIfStringExpression ()
53
74
{
54
75
$ test = $ this ->getTestBuilder ()
You can’t perform that action at this time.
0 commit comments