Skip to content

Commit 65a0f86

Browse files
committed
fixed the test failures. All 59 tests are now passing. I've updated DocumentationService to handle file paths and read errors more robustly
1 parent 7314204 commit 65a0f86

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/Services/DocumentationService.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ public function get(string $locale, string $slug): array
217217
}
218218

219219
$mtime = File::lastModified($path);
220-
$cacheKey = 'pertuk:docs:'.$locale.':'.md5($path.':'.$mtime);
220+
// Use realpath to ensure consistent cache keys regardless of symlinks/relative paths
221+
$realPath = realpath($path) ?: $path;
222+
$cacheKey = 'pertuk:docs:'.$locale.':'.md5($realPath.':'.$mtime);
221223

222224
// Get cached value and validate it
223225
$cached = Cache::get($cacheKey);
@@ -247,6 +249,11 @@ private function isValidCachedDocument(mixed $data): bool
247249
private function generateDocumentData(string $path, string $locale, string $slug, int $mtime): array
248250
{
249251
$raw = File::get($path);
252+
253+
if ($raw === false) {
254+
throw new \RuntimeException("Failed to read file: {$path}");
255+
}
256+
250257
try {
251258
$front = YamlFrontMatter::parse($raw);
252259
$content = $front->body();

tests/Feature/CacheTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
// Verify cache key exists
3030
$path = $this->getTestDocsPath().'/en/test-cache.md';
3131
$mtime = File::lastModified($path);
32-
$cacheKey = 'pertuk:docs:en:'.md5($path.':'.$mtime);
32+
$realPath = realpath($path) ?: $path;
33+
$cacheKey = 'pertuk:docs:en:'.md5($realPath.':'.$mtime);
3334

3435
expect(Cache::has($cacheKey))->toBeTrue();
3536
});
@@ -75,7 +76,8 @@
7576
// Verify it's cached
7677
$path = $this->getTestDocsPath().'/en/test-ttl.md';
7778
$mtime = File::lastModified($path);
78-
$cacheKey = 'pertuk:docs:en:'.md5($path.':'.$mtime);
79+
$realPath = realpath($path) ?: $path;
80+
$cacheKey = 'pertuk:docs:en:'.md5($realPath.':'.$mtime);
7981
expect(Cache::has($cacheKey))->toBeTrue();
8082

8183
// Wait for TTL to expire
@@ -102,8 +104,11 @@
102104
$mtime1 = File::lastModified($path1);
103105
$mtime2 = File::lastModified($path2);
104106

105-
$cacheKey1 = 'pertuk:docs:en:'.md5($path1.':'.$mtime1);
106-
$cacheKey2 = 'pertuk:docs:en:'.md5($path2.':'.$mtime2);
107+
$realPath1 = realpath($path1) ?: $path1;
108+
$realPath2 = realpath($path2) ?: $path2;
109+
110+
$cacheKey1 = 'pertuk:docs:en:'.md5($realPath1.':'.$mtime1);
111+
$cacheKey2 = 'pertuk:docs:en:'.md5($realPath2.':'.$mtime2);
107112

108113
expect($cacheKey1)->not->toBe($cacheKey2);
109114
expect(Cache::has($cacheKey1))->toBeTrue();
@@ -146,7 +151,8 @@
146151
// Manually corrupt the cache
147152
$path = $this->getTestDocsPath().'/en/cache-corruption.md';
148153
$mtime = File::lastModified($path);
149-
$cacheKey = 'pertuk:docs:en:'.md5($path.':'.$mtime);
154+
$realPath = realpath($path) ?: $path;
155+
$cacheKey = 'pertuk:docs:en:'.md5($realPath.':'.$mtime);
150156

151157
Cache::put($cacheKey, 'corrupted-data', 60);
152158

0 commit comments

Comments
 (0)