Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/StaticCaching/StaticCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Statamic\StaticCaching;

use Illuminate\Cache\Repository;
use Illuminate\Support\Facades\Cache;
use Statamic\Events\StaticCacheCleared;
use Statamic\Facades\Site;
Expand Down Expand Up @@ -37,7 +36,7 @@ public function createFileDriver(array $config)

public function createApplicationDriver(array $config)
{
return new ApplicationCacher($this->app[Repository::class], $config);
return new ApplicationCacher($this->cacheStore(), $config);
}

public function cacheStore()
Expand Down
39 changes: 39 additions & 0 deletions tests/StaticCaching/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,49 @@
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\StaticCache;
use Statamic\StaticCaching\Cacher;
use Statamic\StaticCaching\Cachers\ApplicationCacher;
use Tests\TestCase;

class ManagerTest extends TestCase
{
#[Test]
public function application_driver_uses_the_default_cache_store_when_no_custom_store_is_defined()
{
config([
'statamic.static_caching.strategy' => 'half',
'statamic.static_caching.strategies.half.driver' => 'application',
]);

$cacher = StaticCache::driver();

$this->assertInstanceOf(ApplicationCacher::class, $cacher);
$this->assertSame(Cache::store(), $this->getCacherCache($cacher));
}

#[Test]
public function application_driver_uses_the_custom_static_cache_store_when_defined()
{
config([
'statamic.static_caching.strategy' => 'half',
'statamic.static_caching.strategies.half.driver' => 'application',
'cache.stores.static_cache' => ['driver' => 'array'],
]);

$cacher = StaticCache::driver();

$this->assertInstanceOf(ApplicationCacher::class, $cacher);
$this->assertSame(Cache::store('static_cache'), $this->getCacherCache($cacher));
$this->assertNotSame(Cache::store(), $this->getCacherCache($cacher));
}

private function getCacherCache(ApplicationCacher $cacher)
{
$property = new \ReflectionProperty($cacher, 'cache');
$property->setAccessible(true);

return $property->getValue($cacher);
}

#[Test]
public function it_flushes()
{
Expand Down
Loading