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
2 changes: 1 addition & 1 deletion packages/view/src/Initializers/ViewCacheInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ private function shouldCacheBeEnabled(): bool
return false;
}

return (bool) env('VIEW_CACHE', default: Environment::guessFromEnvironment());
return (bool) env('VIEW_CACHE', default: Environment::guessFromEnvironment()->requiresCaution());
}
}
57 changes: 57 additions & 0 deletions tests/Integration/View/ViewCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\Tempest\Integration\View;

use PHPUnit\Framework\Attributes\Test;
use Tempest\View\ViewCache;
use Tempest\View\ViewCachePool;
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
Expand Down Expand Up @@ -42,9 +43,65 @@ protected function tearDown(): void
rmdir(self::DIRECTORY);
}

putenv('ENVIRONMENT=testing');
putenv('VIEW_CACHE=');
putenv('INTERNAL_CACHES=');

parent::tearDown();
}

#[Test]
public function enabled_by_default_in_production(): void
{
putenv('ENVIRONMENT=production');

$this->container->unregister(ViewCache::class);

$this->assertTrue($this->container->get(ViewCache::class)->enabled);
}

#[Test]
public function enabled_by_default_in_staging(): void
{
putenv('ENVIRONMENT=staging');

$this->container->unregister(ViewCache::class);

$this->assertTrue($this->container->get(ViewCache::class)->enabled);
}

#[Test]
public function disabled_by_default_locally(): void
{
putenv('ENVIRONMENT=local');

$this->container->unregister(ViewCache::class);

$this->assertFalse($this->container->get(ViewCache::class)->enabled);
}

#[Test]
public function overriden_by_internal_caches_in_production(): void
{
putenv('ENVIRONMENT=production');
putenv('INTERNAL_CACHES=false');

$this->container->unregister(ViewCache::class);

$this->assertFalse($this->container->get(ViewCache::class)->enabled);
}

#[Test]
public function overriden_by_view_cache_locally(): void
{
putenv('ENVIRONMENT=local');
putenv('VIEW_CACHE=true');

$this->container->unregister(ViewCache::class);

$this->assertTrue($this->container->get(ViewCache::class)->enabled);
}

public function test_view_cache(): void
{
$path = $this->viewCache->getCachedViewPath('path', fn () => 'hi');
Expand Down