Skip to content

Commit b730fd7

Browse files
committed
feat: add version option and test
1 parent 04bc2df commit b730fd7

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

config/image-transform-url.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
'quality',
4343
'flip',
4444
'contrast',
45+
'version',
4546
// 'blur'
4647
]),
4748

src/Enums/AllowedOptions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum AllowedOptions: string
1313
case Blur = 'blur';
1414
case Contrast = 'contrast';
1515
case Flip = 'flip';
16+
case Version = 'version';
1617

1718
public static function all(): array
1819
{
@@ -29,6 +30,7 @@ public static function withTypes(): array
2930
self::Blur->value => 'integer',
3031
self::Contrast->value => 'integer',
3132
self::Flip->value => 'string',
33+
self::Version->value => 'integer',
3234
];
3335
}
3436
}

tests/Feature/CacheTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,31 @@
2727
$response->assertOk();
2828
$secondResponse->assertHeader('X-Cache', 'HIT');
2929
});
30+
31+
it('can use the version option to revalidate the cache', function () {
32+
/** @var TestCase $this */
33+
34+
$response = $this->get(route('image.transform', [
35+
'options' => 'version=1',
36+
'path' => 'cat.jpg',
37+
]));
38+
39+
$response->assertOk();
40+
$response->assertHeader('X-Cache', 'MISS');
41+
42+
$sameVersionResponse = $this->get(route('image.transform', [
43+
'options' => 'version=1',
44+
'path' => 'cat.jpg',
45+
]));
46+
47+
$sameVersionResponse->assertOk();
48+
$sameVersionResponse->assertHeader('X-Cache', 'HIT');
49+
50+
$differentVersionResponse = $this->get(route('image.transform', [
51+
'options' => 'version=2',
52+
'path' => 'cat.jpg',
53+
]));
54+
55+
$differentVersionResponse->assertOk();
56+
$differentVersionResponse->assertHeader('X-Cache', 'MISS');
57+
});

0 commit comments

Comments
 (0)