|
| 1 | +<?php |
| 2 | + |
| 3 | +test('cache configuration uses CACHE_STORE in Laravel 12', function () { |
| 4 | + // Mock the configuration to simulate Laravel 12 with CACHE_STORE |
| 5 | + config([ |
| 6 | + 'laravel-docuware.configurations.cache.driver' => 'redis', |
| 7 | + ]); |
| 8 | + |
| 9 | + // Test that the configuration is properly loaded |
| 10 | + $cacheDriver = config('laravel-docuware.configurations.cache.driver'); |
| 11 | + expect($cacheDriver)->toBe('redis'); |
| 12 | +}); |
| 13 | + |
| 14 | +test('cache configuration falls back to CACHE_DRIVER when CACHE_STORE is not set', function () { |
| 15 | + // Mock the configuration to simulate older Laravel versions |
| 16 | + config([ |
| 17 | + 'laravel-docuware.configurations.cache.driver' => 'file', |
| 18 | + ]); |
| 19 | + |
| 20 | + // Test that the configuration is properly loaded |
| 21 | + $cacheDriver = config('laravel-docuware.configurations.cache.driver'); |
| 22 | + expect($cacheDriver)->toBe('file'); |
| 23 | +}); |
| 24 | + |
| 25 | +test('cache configuration uses DOCUWARE_CACHE_DRIVER when explicitly set', function () { |
| 26 | + // Mock the configuration to prioritize DOCUWARE_CACHE_DRIVER |
| 27 | + config([ |
| 28 | + 'laravel-docuware.configurations.cache.driver' => 'array', |
| 29 | + ]); |
| 30 | + |
| 31 | + // Test that the configuration is properly loaded |
| 32 | + $cacheDriver = config('laravel-docuware.configurations.cache.driver'); |
| 33 | + expect($cacheDriver)->toBe('array'); |
| 34 | +}); |
| 35 | + |
| 36 | +test('cache configuration respects the new CACHE_STORE fallback chain', function () { |
| 37 | + // Test that the configuration properly uses the new fallback chain: |
| 38 | + // DOCUWARE_CACHE_DRIVER -> CACHE_STORE -> CACHE_DRIVER -> 'file' |
| 39 | + |
| 40 | + // Mock the configuration to simulate the fallback chain |
| 41 | + config([ |
| 42 | + 'laravel-docuware.configurations.cache.driver' => 'redis', // This would be set by CACHE_STORE |
| 43 | + ]); |
| 44 | + |
| 45 | + // Test that the configuration is properly loaded |
| 46 | + $cacheDriver = config('laravel-docuware.configurations.cache.driver'); |
| 47 | + expect($cacheDriver)->toBe('redis'); |
| 48 | +}); |
| 49 | + |
| 50 | +test('cache configuration uses default file driver when no configuration is set', function () { |
| 51 | + // Reset the configuration to test default behavior |
| 52 | + config([ |
| 53 | + 'laravel-docuware.configurations.cache.driver' => 'file', |
| 54 | + ]); |
| 55 | + |
| 56 | + // Test that the configuration is properly loaded |
| 57 | + $cacheDriver = config('laravel-docuware.configurations.cache.driver'); |
| 58 | + expect($cacheDriver)->toBe('file'); |
| 59 | +}); |
| 60 | + |
| 61 | +test('environment variable fallback chain works correctly', function () { |
| 62 | + // Test that the environment variable fallback chain works as expected |
| 63 | + // This simulates the actual configuration loading logic |
| 64 | + |
| 65 | + // Mock the environment variables |
| 66 | + putenv('DOCUWARE_CACHE_DRIVER=array'); |
| 67 | + putenv('CACHE_STORE=redis'); |
| 68 | + putenv('CACHE_DRIVER=file'); |
| 69 | + |
| 70 | + // The configuration should prioritize DOCUWARE_CACHE_DRIVER |
| 71 | + $expectedDriver = env('DOCUWARE_CACHE_DRIVER', env('CACHE_STORE', env('CACHE_DRIVER', 'file'))); |
| 72 | + expect($expectedDriver)->toBe('array'); |
| 73 | + |
| 74 | + // Clean up |
| 75 | + putenv('DOCUWARE_CACHE_DRIVER'); |
| 76 | + putenv('CACHE_STORE'); |
| 77 | + putenv('CACHE_DRIVER'); |
| 78 | +}); |
| 79 | + |
| 80 | +test('CACHE_STORE takes precedence over CACHE_DRIVER when DOCUWARE_CACHE_DRIVER is not set', function () { |
| 81 | + // Mock the environment variables |
| 82 | + putenv('DOCUWARE_CACHE_DRIVER='); |
| 83 | + putenv('CACHE_STORE=redis'); |
| 84 | + putenv('CACHE_DRIVER=file'); |
| 85 | + |
| 86 | + // The configuration should use CACHE_STORE when DOCUWARE_CACHE_DRIVER is not set |
| 87 | + $expectedDriver = env('DOCUWARE_CACHE_DRIVER', env('CACHE_STORE', env('CACHE_DRIVER', 'file'))); |
| 88 | + expect($expectedDriver)->toBe('redis'); |
| 89 | + |
| 90 | + // Clean up |
| 91 | + putenv('DOCUWARE_CACHE_DRIVER'); |
| 92 | + putenv('CACHE_STORE'); |
| 93 | + putenv('CACHE_DRIVER'); |
| 94 | +}); |
0 commit comments