@@ -28,6 +28,17 @@ class DeploymentConfig
28
28
*/
29
29
private $ config ;
30
30
31
+ /**
32
+ * Ignore values in the config nested array, paths are separated by single slash "/".
33
+ *
34
+ * Example: compiled_config is not set in default mode, and once set it can't be unset
35
+ *
36
+ * @var array
37
+ */
38
+ private $ ignoreValues = [
39
+ 'cache_types/compiled_config ' ,
40
+ ];
41
+
31
42
/**
32
43
* Memorizes the initial value of configuration reader and the configuration value
33
44
*
@@ -57,11 +68,7 @@ public function startTestSuite()
57
68
*/
58
69
public function endTest (\PHPUnit \Framework \TestCase $ test )
59
70
{
60
- $ config = $ this ->reader ->load ();
61
- // ignore compiled_config setting because is not set in default mode
62
- if (isset ($ config ['cache_types ' ]['compiled_config ' ])) {
63
- unset($ config ['cache_types ' ]['compiled_config ' ]);
64
- }
71
+ $ config = $ this ->filterIgnoredConfigValues ($ this ->reader ->load ());
65
72
if ($ this ->config != $ config ) {
66
73
$ error = "\n\nERROR: deployment configuration is corrupted. The application state is no longer valid. \n"
67
74
. 'Further tests may fail. '
@@ -70,4 +77,27 @@ public function endTest(\PHPUnit\Framework\TestCase $test)
70
77
$ test ->fail ($ error );
71
78
}
72
79
}
80
+
81
+ /**
82
+ * Filter ignored config values which are not set by default and appear when tests would change state.
83
+ *
84
+ * Example: compiled_config is not set in default mode, and once set it can't be unset
85
+ *
86
+ * @param array $config
87
+ * @param string $path
88
+ * @return array
89
+ */
90
+ private function filterIgnoredConfigValues (array $ config , string $ path = '' ) {
91
+ foreach ($ config as $ configKeyName => $ configValue ) {
92
+ $ newPath = !empty ($ path ) ? $ path . '/ ' . $ configKeyName : $ configKeyName ;
93
+ if (is_array ($ configValue )) {
94
+ $ config [$ configKeyName ] = $ this ->filterIgnoredConfigValues ($ configValue , $ newPath );
95
+ } else {
96
+ if (array_key_exists ($ newPath , array_flip ($ this ->ignoreValues ))) {
97
+ unset($ config [$ configKeyName ]);
98
+ }
99
+ }
100
+ }
101
+ return $ config ;
102
+ }
73
103
}
0 commit comments