File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ CHANGELOG
88 * added second ` $exists ` constructor argument to ` ClassExistenceResource `
99 * made ` ClassExistenceResource ` work with interfaces and traits
1010 * added ` ConfigCachePass ` (originally in FrameworkBundle)
11+ * added ` castToArray() ` helper to turn any config value into an array
1112
12133.0.0
1314-----
@@ -36,7 +37,7 @@ Before: `InvalidArgumentException` (variable must contain at least two
3637distinct elements).
3738After: the code will work as expected and it will restrict the values of the
3839` variable ` option to just ` value ` .
39-
40+
4041 * deprecated the ` ResourceInterface::isFresh() ` method. If you implement custom resource types and they
4142 can be validated that way, make them implement the new ` SelfCheckingResourceInterface ` .
4243 * deprecated the getResource() method in ResourceInterface. You can still call this method
@@ -49,7 +50,7 @@ After: the code will work as expected and it will restrict the values of the
4950
5051 * added ` ConfigCacheInterface ` , ` ConfigCacheFactoryInterface ` and a basic ` ConfigCacheFactory `
5152 implementation to delegate creation of ConfigCache instances
52-
53+
53542.2.0
5455-----
5556
Original file line number Diff line number Diff line change @@ -149,6 +149,19 @@ public function ifNotInArray(array $array)
149149 return $ this ;
150150 }
151151
152+ /**
153+ * Transforms variables of any type into an array.
154+ *
155+ * @return $this
156+ */
157+ public function castToArray ()
158+ {
159+ $ this ->ifPart = function ($ v ) { return !is_array ($ v ); };
160+ $ this ->thenPart = function ($ v ) { return array ($ v ); };
161+
162+ return $ this ;
163+ }
164+
152165 /**
153166 * Sets the closure to run if the test pass.
154167 *
Original file line number Diff line number Diff line change @@ -145,6 +145,25 @@ public function testThenEmptyArrayExpression()
145145 $ this ->assertFinalizedValueIs (array (), $ test );
146146 }
147147
148+ /**
149+ * @dataProvider castToArrayValues
150+ */
151+ public function testcastToArrayExpression ($ configValue , $ expectedValue )
152+ {
153+ $ test = $ this ->getTestBuilder ()
154+ ->castToArray ()
155+ ->end ();
156+ $ this ->assertFinalizedValueIs ($ expectedValue , $ test , array ('key ' => $ configValue ));
157+ }
158+
159+ public function castToArrayValues ()
160+ {
161+ yield array ('value ' , array ('value ' ));
162+ yield array (-3.14 , array (-3.14 ));
163+ yield array (null , array (null ));
164+ yield array (array ('value ' ), array ('value ' ));
165+ }
166+
148167 /**
149168 * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
150169 */
You can’t perform that action at this time.
0 commit comments