Skip to content

Commit d05dea9

Browse files
authored
Make Asset::clearCaches protected (#308)
* Add asset blink test * Bump core requirement
1 parent 4155c76 commit d05dea9

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"require": {
2727
"php": "^8.1",
28-
"statamic/cms": "^5.7"
28+
"statamic/cms": "^5.12"
2929
},
3030
"require-dev": {
3131
"doctrine/dbal": "^3.8",

src/Assets/Asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function getCurrentDirtyStateAttributes(): array
223223
]);
224224
}
225225

226-
private function clearCaches()
226+
protected function clearCaches()
227227
{
228228
$this->meta = null;
229229

tests/Assets/AssetTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Tests\Assets;
4+
5+
use Illuminate\Foundation\Testing\RefreshDatabase;
6+
use Illuminate\Support\Facades\Storage;
7+
use Statamic\Facades;
8+
use Tests\TestCase;
9+
10+
class AssetTest extends TestCase
11+
{
12+
use RefreshDatabase;
13+
14+
private $container;
15+
16+
public function setUp(): void
17+
{
18+
parent::setUp();
19+
20+
Storage::fake('test', ['url' => '/assets']);
21+
22+
$this->container = tap(Facades\AssetContainer::make('test')->disk('test'))->save();
23+
24+
Storage::disk('test')->put('a.jpg', '');
25+
Facades\Asset::make()->container('test')->path('a.jpg')->save();
26+
27+
Storage::disk('test')->put('b.txt', '');
28+
Facades\Asset::make()->container('test')->path('b.txt')->save();
29+
30+
Storage::disk('test')->put('c.txt', '');
31+
Facades\Asset::make()->container('test')->path('c.txt')->save();
32+
33+
Storage::disk('test')->put('d.jpg', '');
34+
Facades\Asset::make()->container('test')->path('d.jpg')->save();
35+
36+
Storage::disk('test')->put('e.jpg', '');
37+
Facades\Asset::make()->container('test')->path('e.jpg')->save();
38+
39+
Storage::disk('test')->put('f.jpg', '');
40+
Facades\Asset::make()->container('test')->path('f.jpg')->save();
41+
}
42+
43+
/** @test */
44+
public function saving_an_asset_clears_the_eloquent_blink_cache()
45+
{
46+
$asset = Facades\Asset::find('test::f.jpg');
47+
48+
$this->assertTrue(Facades\Blink::has("eloquent-asset-{$asset->id()}"));
49+
50+
$asset->save();
51+
52+
$this->assertFalse(Facades\Blink::has("eloquent-asset-{$asset->id()}"));
53+
}
54+
}

0 commit comments

Comments
 (0)