Add configuration system tests for Only and Except combinations.

This commit is contained in:
Mateusz Uzdowski 2013-07-02 15:51:53 +12:00
parent df218d76da
commit f9ede95e5b
3 changed files with 90 additions and 2 deletions

View File

@ -260,7 +260,10 @@ Note than when you have more than one rule for a nested fragment, they're joined
FRAGMENT_INCLUDED = (ONLY && ONLY) && !(EXCEPT && EXCEPT)
That is, the fragment will be included if all Only rules match, except if all Except rules match
That is, the fragment will be included if all Only rules match, except if all Except rules match.
Also, due to YAML limitations, having multiple conditions of the same kind (say, two `EnvVarSet` in one "Only" block)
will result in only the latter coming through.
### The values

View File

@ -140,6 +140,41 @@ class ConfigManifestTest extends SapphireTest {
Config::inst()->unnest();
}
public function testMultipleRules() {
$_ENV['MultilpleRules_EnvVariableSet'] = 1;
define('MultilpleRules_DefinedConstant', 'defined');
$config = $this->getConfigFixtureValue('MultipleRules');
$this->assertFalse(
isset($config['TwoOnlyFail']),
'Fragment is not included if one of the Only rules fails.'
);
$this->assertTrue(
isset($config['TwoOnlySucceed']),
'Fragment is included if both Only rules succeed.'
);
$this->assertTrue(
isset($config['TwoExceptSucceed']),
'Fragment is included if one of the Except rules matches.'
);
$this->assertFalse(
isset($config['TwoExceptFail']),
'Fragment is not included if both of the Except rules fail.'
);
$this->assertFalse(
isset($config['TwoBlocksFail']),
'Fragment is not included if one block fails.'
);
$this->assertTrue(
isset($config['TwoBlocksSucceed']),
'Fragment is included if both blocks succeed.'
);
}
public function testRelativeOrder() {
$accessor = new ConfigManifestTest_ConfigManifestAccess(BASE_PATH, true, false);
@ -221,4 +256,4 @@ class ConfigManifestTest extends SapphireTest {
), 'after');
}
}
}

View File

@ -0,0 +1,50 @@
---
Only:
ConstantDefined: MultilpleRules_UndefinedConstant
EnvVarSet: MultilpleRules_EnvVariableSet
---
ConfigManifestTest:
MultipleRules:
TwoOnlyFail: "not included - one of the onlies fails"
---
Only:
ConstantDefined: MultilpleRules_DefinedConstant
EnvVarSet: MultilpleRules_EnvVariableSet
---
ConfigManifestTest:
MultipleRules:
TwoOnlySucceed: "included - both onlies succeed"
---
Except:
ConstantDefined: MultilpleRules_UndefinedConstant
EnvVarSet: MultilpleRules_EnvVariableSet
---
ConfigManifestTest:
MultipleRules:
TwoExceptSucceed: "included - one of the excepts succeeds"
---
Except:
ConstantDefined: MultilpleRules_DefinedConstant
EnvVarSet: MultilpleRules_EnvVariableSet
---
ConfigManifestTest:
MultipleRules:
TwoExceptFail: "not included - both excepts fail"
---
Except:
EnvVarSet: MultilpleRules_EnvVariableSet
Only:
EnvVarSet: MultilpleRules_EnvVariableSet
---
ConfigManifestTest:
MultipleRules:
TwoBlocksFail: "not included - one block fails"
---
Except:
ConstantDefined: MultilpleRules_UndefinedConstant
Only:
EnvVarSet: MultilpleRules_EnvVariableSet
---
ConfigManifestTest:
MultipleRules:
TwoBlocksSucceed: "included - both blocks succeed"