12
12
namespace Symfony \Component \Config \Tests \Definition ;
13
13
14
14
use Symfony \Component \Config \Definition \ArrayNode ;
15
+ use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
15
16
use Symfony \Component \Config \Definition \ScalarNode ;
16
17
17
18
class ArrayNodeTest extends \PHPUnit_Framework_TestCase
@@ -35,34 +36,30 @@ public function testExceptionThrownOnUnrecognizedChild()
35
36
$ node ->normalize (array ('foo ' => 'bar ' ));
36
37
}
37
38
38
- /**
39
- * Tests that no exception is thrown for an unrecognized child if the
40
- * ignoreExtraKeys option is set to true.
41
- *
42
- * Related to testExceptionThrownOnUnrecognizedChild
43
- */
44
- public function testIgnoreExtraKeysNoException ()
39
+ public function ignoreAndRemoveMatrixProvider ()
45
40
{
46
- $ node = new ArrayNode ('roo ' );
47
- $ node ->setIgnoreExtraKeys (true );
41
+ $ unrecognizedOptionException = new InvalidConfigurationException ('Unrecognized option "foo" under "root" ' );
48
42
49
- $ node ->normalize (array ('foo ' => 'bar ' ));
50
- $ this ->assertTrue (true , 'No exception was thrown when setIgnoreExtraKeys is true ' );
43
+ return array (
44
+ array (true , true , array (), 'no exception is thrown for an unrecognized child if the ignoreExtraKeys option is set to true ' ),
45
+ array (true , false , array ('foo ' => 'bar ' ), 'extra keys are not removed when ignoreExtraKeys second option is set to false ' ),
46
+ array (false , true , $ unrecognizedOptionException ),
47
+ array (false , false , $ unrecognizedOptionException ),
48
+ );
51
49
}
52
50
53
51
/**
54
- * Tests that extra keys are not removed when
55
- * ignoreExtraKeys second option is set to false.
56
- *
57
- * Related to testExceptionThrownOnUnrecognizedChild
52
+ * @dataProvider ignoreAndRemoveMatrixProvider
58
53
*/
59
- public function testIgnoreExtraKeysNotRemoved ( )
54
+ public function testIgnoreAndRemoveBehaviors ( $ ignore , $ remove , $ expected , $ message = '' )
60
55
{
61
- $ node = new ArrayNode ('roo ' );
62
- $ node ->setIgnoreExtraKeys (true , false );
63
-
64
- $ data = array ('foo ' => 'bar ' );
65
- $ this ->assertSame ($ data , $ node ->normalize ($ data ));
56
+ if ($ expected instanceof \Exception) {
57
+ $ this ->setExpectedException (get_class ($ expected ), $ expected ->getMessage ());
58
+ }
59
+ $ node = new ArrayNode ('root ' );
60
+ $ node ->setIgnoreExtraKeys ($ ignore , $ remove );
61
+ $ result = $ node ->normalize (array ('foo ' => 'bar ' ));
62
+ $ this ->assertSame ($ expected , $ result , $ message );
66
63
}
67
64
68
65
/**
0 commit comments