diff --git a/core/manifest/ConfigManifest.php b/core/manifest/ConfigManifest.php index af04ae9e9..e9091bf6f 100644 --- a/core/manifest/ConfigManifest.php +++ b/core/manifest/ConfigManifest.php @@ -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 (false === $this->variantKeySpec) { + if (false === $this->phpConfigSources || false === $this->variantKeySpec) { $this->regenerate($includeTests); } diff --git a/tests/core/manifest/ConfigManifestTest.php b/tests/core/manifest/ConfigManifestTest.php index a1fac8424..5b14df254 100644 --- a/tests/core/manifest/ConfigManifestTest.php +++ b/tests/core/manifest/ConfigManifestTest.php @@ -152,6 +152,83 @@ class ConfigManifestTest extends SapphireTest { $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 method uses fixture/configmanifest/mysite/_config/addyamlconfigfile.yml as a fixture