|
| 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