Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ConfigAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions test/ConfigAggregatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this assert an array that matches the input configuration? i.e. self::assertSame([], $aggregator->getMergedConfig()); - also, when the cache file is empty, do we expect the cache file to be updated with the now cached config?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, @gsteel. I'll take another look tonight.

}

public function testConfigAggregatorCanLoadConfigFromCache(): void
{
$expected = [
Expand Down