Skip to content

Commit ce1efad

Browse files
committed
Fix assetsAreCurrent to respect assets_path config
The assetsAreCurrent method was hardcoded to check the default 'vendor/log-viewer' path, ignoring the configurable assets_path. This caused false negatives when assets were published to a custom location.
1 parent d244fb6 commit ce1efad

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/LogViewerService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public function getViewLayout(): string
346346
*/
347347
public function assetsAreCurrent(): bool
348348
{
349-
$publishedPath = public_path('vendor/log-viewer/mix-manifest.json');
349+
$publishedPath = public_path(Str::finish(config('log-viewer.assets_path'), '/').'mix-manifest.json');
350350

351351
if (! File::exists($publishedPath)) {
352352
throw new \RuntimeException('Log Viewer assets are not published. Please run: php artisan vendor:publish --tag=log-viewer-assets --force');
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\File;
4+
use Opcodes\LogViewer\Facades\LogViewer;
5+
6+
beforeEach(function () {
7+
// Ensure the source manifest exists
8+
File::ensureDirectoryExists(__DIR__.'/../../public');
9+
if (! File::exists(__DIR__.'/../../public/mix-manifest.json')) {
10+
File::put(__DIR__.'/../../public/mix-manifest.json', '{"test": "source"}');
11+
}
12+
});
13+
14+
test('assetsAreCurrent returns true when published manifest matches source', function () {
15+
$publishedPath = public_path('vendor/log-viewer/mix-manifest.json');
16+
$sourcePath = __DIR__.'/../../public/mix-manifest.json';
17+
18+
File::ensureDirectoryExists(dirname($publishedPath));
19+
File::copy($sourcePath, $publishedPath);
20+
21+
expect(LogViewer::assetsAreCurrent())->toBeTrue();
22+
23+
File::delete($publishedPath);
24+
});
25+
26+
test('assetsAreCurrent returns false when published manifest differs from source', function () {
27+
$publishedPath = public_path('vendor/log-viewer/mix-manifest.json');
28+
29+
File::ensureDirectoryExists(dirname($publishedPath));
30+
File::put($publishedPath, '{"test": "different"}');
31+
32+
expect(LogViewer::assetsAreCurrent())->toBeFalse();
33+
34+
File::delete($publishedPath);
35+
});
36+
37+
test('assetsAreCurrent throws exception when published assets do not exist', function () {
38+
$publishedPath = public_path('vendor/log-viewer/mix-manifest.json');
39+
40+
if (File::exists($publishedPath)) {
41+
File::delete($publishedPath);
42+
}
43+
44+
LogViewer::assetsAreCurrent();
45+
})->throws(
46+
RuntimeException::class,
47+
'Log Viewer assets are not published. Please run: php artisan vendor:publish --tag=log-viewer-assets --force'
48+
);
49+
50+
test('assetsAreCurrent respects custom assets_path config', function () {
51+
$customPath = 'custom-log-viewer-path';
52+
config(['log-viewer.assets_path' => $customPath]);
53+
54+
$publishedPath = public_path($customPath.'/mix-manifest.json');
55+
$sourcePath = __DIR__.'/../../public/mix-manifest.json';
56+
57+
File::ensureDirectoryExists(dirname($publishedPath));
58+
File::copy($sourcePath, $publishedPath);
59+
60+
expect(LogViewer::assetsAreCurrent())->toBeTrue();
61+
62+
File::deleteDirectory(public_path($customPath));
63+
});

0 commit comments

Comments
 (0)