diff --git a/src/ConfigAggregator.php b/src/ConfigAggregator.php index 82fc43c..db1e9ea 100644 --- a/src/ConfigAggregator.php +++ b/src/ConfigAggregator.php @@ -17,6 +17,7 @@ use function class_exists; use function date; use function file_exists; +use function filesize; use function gettype; use function is_array; use function is_callable; @@ -257,6 +258,10 @@ private function loadConfigFromCache(null|string $cachedConfigFile): bool return false; } + if (filesize($cachedConfigFile) === 0) { + return false; + } + $this->config = require $cachedConfigFile; return true; } diff --git a/test/ConfigAggregatorTest.php b/test/ConfigAggregatorTest.php index 8e8704e..6e644bf 100644 --- a/test/ConfigAggregatorTest.php +++ b/test/ConfigAggregatorTest.php @@ -230,6 +230,14 @@ public function testConfigAggregatorSetsHandlesUnwritableCache(): void self::assertFileDoesNotExist($this->cacheFile); } + public function testConfigAggregatorDoesNotLoadConfigFromCacheIfCacheFileIsEmpty(): void + { + file_put_contents($this->cacheFile, ''); + $aggregator = new ConfigAggregator([], $this->cacheFile); + + self::assertEmpty($aggregator->getMergedConfig()); + } + public function testConfigAggregatorCanLoadConfigFromCache(): void { $expected = [