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 11CHANGELOG
22=========
33
4+ 7.3
5+ ---
6+
7+ * Add ` ExprBuilder::ifFalse() `
8+
497.2
510---
611
Original file line number Diff line number Diff line change @@ -67,6 +67,21 @@ public function ifTrue(?\Closure $closure = null): static
6767 return $ this ;
6868 }
6969
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+
7085 /**
7186 * Tests if the value is a string.
7287 *
Original file line number Diff line number Diff line change @@ -49,6 +49,27 @@ public function testIfTrueExpression()
4949 $ this ->assertFinalizedValueIs ('value ' , $ test );
5050 }
5151
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+
5273 public function testIfStringExpression ()
5374 {
5475 $ test = $ this ->getTestBuilder ()
You can’t perform that action at this time.
0 commit comments