Merge pull request #6513 from sb-relaxt-at/3.4-backport-6467-ConfigManifest-validate-existence-of-cache-files

BUG Ensure correct regeneration of ConfigManifest if only one of the …
This commit is contained in:
Daniel Hensby 2017-01-16 20:58:11 +00:00 committed by GitHub
commit f1edbed53f
2 changed files with 78 additions and 1 deletions

View File

@ -99,7 +99,7 @@ class SS_ConfigManifest {
} }
// If we don't have a variantKeySpec (because we're forcing regen, or it just wasn't in the cache), generate it // If we don't have a variantKeySpec (because we're forcing regen, or it just wasn't in the cache), generate it
if (false === $this->variantKeySpec) { if (false === $this->phpConfigSources || false === $this->variantKeySpec) {
$this->regenerate($includeTests); $this->regenerate($includeTests);
} }

View File

@ -152,6 +152,83 @@ class ConfigManifestTest extends SapphireTest {
$manifest->__construct(dirname(__FILE__).'/fixtures/configmanifest', false, false); $manifest->__construct(dirname(__FILE__).'/fixtures/configmanifest', false, false);
} }
/**
* Test cache regeneration if all or some of the cache files are missing
*
* 1. Test regeneration if all cache files are missing
* 2. Test regeneration if 'variant_key_spec' cache file is missing
* 3. Test regeneration if 'php_config_sources' cache file is missing
*/
public function testAutomaticCacheRegeneration(){
$base = dirname(__FILE__) . '/fixtures/configmanifest';
// Test regeneration if all cache files are missing
$manifest = $this->getManifestMock(array('getCache', 'regenerate', 'buildYamlConfigVariant'));
$manifest->expects($this->once())// regenerate should be called once
->method('regenerate')
->with($this->equalTo(false)); // includeTests = false
// Set up a cache where we expect load to never be called
$cache = $this->getCacheMock();
$cache->expects($this->exactly(2))
->will($this->returnValue(false))
->method('load');
$manifest->expects($this->any())
->method('getCache')
->will($this->returnValue($cache));
$manifest->__construct($base);
// Test regeneration if 'variant_key_spec' cache file is missing
$manifest = $this->getManifestMock(array('getCache', 'regenerate', 'buildYamlConfigVariant'));
$manifest->expects($this->once())// regenerate should be called once
->method('regenerate')
->with($this->equalTo(false)); // includeTests = false
$cache = $this->getCacheMock();
$cache->expects($this->exactly(2))
->method('load')
->will($this->returnCallback(function ($parameter) {
if (strpos($parameter, 'variant_key_spec') !== false) {
return false;
}
return array();
}));
$manifest->expects($this->any())
->method('getCache')
->will($this->returnValue($cache));
$manifest->__construct($base);
// Test regeneration if 'php_config_sources' cache file is missing
$manifest = $this->getManifestMock(array('getCache', 'regenerate', 'buildYamlConfigVariant'));
$manifest->expects($this->once())// regenerate should be called once
->method('regenerate')
->with($this->equalTo(false)); // includeTests = false
$cache = $this->getCacheMock();
$cache->expects($this->exactly(2))
->method('load')
->will($this->returnCallback(function ($parameter) {
if (strpos($parameter, 'php_config_sources') !== false) {
return false;
}
return array();
}));
$manifest->expects($this->any())
->method('getCache')
->will($this->returnValue($cache));
$manifest->__construct($base);
}
/** /**
* This test checks the processing of before and after reference paths (module-name/filename#fragment) * This test checks the processing of before and after reference paths (module-name/filename#fragment)
* This method uses fixture/configmanifest/mysite/_config/addyamlconfigfile.yml as a fixture * This method uses fixture/configmanifest/mysite/_config/addyamlconfigfile.yml as a fixture