Skip to content

Commit

Permalink
Make Asset::clearCaches protected (#308)
Browse files Browse the repository at this point in the history
* Add asset blink test

* Bump core requirement
  • Loading branch information
ryanmitchell authored Jun 29, 2024
1 parent 4155c76 commit d05dea9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require": {
"php": "^8.1",
"statamic/cms": "^5.7"
"statamic/cms": "^5.12"
},
"require-dev": {
"doctrine/dbal": "^3.8",
Expand Down
2 changes: 1 addition & 1 deletion src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function getCurrentDirtyStateAttributes(): array
]);
}

private function clearCaches()
protected function clearCaches()
{
$this->meta = null;

Expand Down
54 changes: 54 additions & 0 deletions tests/Assets/AssetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Tests\Assets;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Statamic\Facades;
use Tests\TestCase;

class AssetTest extends TestCase
{
use RefreshDatabase;

private $container;

public function setUp(): void
{
parent::setUp();

Storage::fake('test', ['url' => '/assets']);

$this->container = tap(Facades\AssetContainer::make('test')->disk('test'))->save();

Storage::disk('test')->put('a.jpg', '');
Facades\Asset::make()->container('test')->path('a.jpg')->save();

Storage::disk('test')->put('b.txt', '');
Facades\Asset::make()->container('test')->path('b.txt')->save();

Storage::disk('test')->put('c.txt', '');
Facades\Asset::make()->container('test')->path('c.txt')->save();

Storage::disk('test')->put('d.jpg', '');
Facades\Asset::make()->container('test')->path('d.jpg')->save();

Storage::disk('test')->put('e.jpg', '');
Facades\Asset::make()->container('test')->path('e.jpg')->save();

Storage::disk('test')->put('f.jpg', '');
Facades\Asset::make()->container('test')->path('f.jpg')->save();
}

/** @test */
public function saving_an_asset_clears_the_eloquent_blink_cache()
{
$asset = Facades\Asset::find('test::f.jpg');

$this->assertTrue(Facades\Blink::has("eloquent-asset-{$asset->id()}"));

$asset->save();

$this->assertFalse(Facades\Blink::has("eloquent-asset-{$asset->id()}"));
}
}

0 comments on commit d05dea9

Please sign in to comment.