Skip to content

Commit 01e6066

Browse files
committed
wip
1 parent 9c52496 commit 01e6066

File tree

6 files changed

+108
-6
lines changed

6 files changed

+108
-6
lines changed

.phpunit.cache/test-results

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to `laravel-docuware` will be documented in this file.
44

5+
## [Unreleased]
6+
7+
### Laravel 12 Compatibility
8+
- Updated cache configuration to use `CACHE_STORE` instead of deprecated `CACHE_DRIVER` for Laravel 12 compatibility
9+
- This ensures DocuWare cache uses the same store as the application, preventing MAC invalid errors when using encrypted cache values
10+
- Maintains backward compatibility with Laravel 9-11 by falling back to `CACHE_DRIVER` if `CACHE_STORE` is not available
11+
512
## 2.0.0 pre-release
613
### General
714
- Dropped support below PHP 8.1

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ return [
17021702
|
17031703
*/
17041704

1705-
'cache_driver' => env('DOCUWARE_CACHE_DRIVER', env('CACHE_DRIVER', 'file')),
1705+
'cache_driver' => env('DOCUWARE_CACHE_DRIVER', env('CACHE_STORE', env('CACHE_DRIVER', 'file'))),
17061706

17071707
/*
17081708
|--------------------------------------------------------------------------
@@ -1765,7 +1765,7 @@ return [
17651765
'additional_result_fields' => [],
17661766
],
17671767
'cache' => [
1768-
'driver' => env('DOCUWARE_CACHE_DRIVER', env('CACHE_DRIVER', 'file')),
1768+
'driver' => env('DOCUWARE_CACHE_DRIVER', env('CACHE_STORE', env('CACHE_DRIVER', 'file'))),
17691769
'lifetime_in_seconds' => env('DOCUWARE_CACHE_LIFETIME_IN_SECONDS', 60),
17701770
],
17711771
],

config/laravel-docuware.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
| Cache driver
88
|--------------------------------------------------------------------------
99
| You may like to define a different cache driver than the default Laravel cache driver.
10+
| In Laravel 12+, CACHE_STORE is used instead of CACHE_DRIVER.
1011
|
1112
*/
1213

13-
'cache_driver' => env('DOCUWARE_CACHE_DRIVER', env('CACHE_DRIVER', 'file')),
14+
'cache_driver' => env('DOCUWARE_CACHE_DRIVER', env('CACHE_STORE', env('CACHE_DRIVER', 'file'))),
1415

1516
/*
1617
|--------------------------------------------------------------------------
@@ -73,7 +74,7 @@
7374
'additional_result_fields' => [],
7475
],
7576
'cache' => [
76-
'driver' => env('DOCUWARE_CACHE_DRIVER', env('CACHE_DRIVER', 'file')),
77+
'driver' => env('DOCUWARE_CACHE_DRIVER', env('CACHE_STORE', env('CACHE_DRIVER', 'file'))),
7778
'lifetime_in_seconds' => env('DOCUWARE_CACHE_LIFETIME_IN_SECONDS', 60),
7879
],
7980
'request' => [

src/DTO/TextshotPage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function fromJson(array $data): self
2323
}
2424

2525
public function __construct(
26-
public string $language,
26+
public ?string $language,
2727
public string $content,
2828
) {}
2929

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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

Comments
 (0)