Skip to content

Commit acf10cb

Browse files
author
Viacheslav Danilin
committed
feat: configurable stub cache via LARAVEL_PLUGIN_CACHE_PATH
1 parent 3bdf847 commit acf10cb

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/Providers/CacheDirectoryProvider.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44

55
namespace Psalm\LaravelPlugin\Providers;
66

7+
use function getenv;
8+
use function rtrim;
9+
710
final class CacheDirectoryProvider
811
{
912
public static function getCacheLocation(): string
1013
{
14+
$env = getenv('LARAVEL_PLUGIN_CACHE_PATH');
15+
if ($env !== false && $env !== '') {
16+
return rtrim($env, '/');
17+
}
18+
1119
return __DIR__ . '/../../cache';
1220
}
1321
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Unit\Providers;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Psalm\LaravelPlugin\Providers\CacheDirectoryProvider;
9+
10+
use function putenv;
11+
use function sys_get_temp_dir;
12+
13+
final class CacheDirectoryProviderTest extends TestCase
14+
{
15+
protected function tearDown(): void
16+
{
17+
putenv('LARAVEL_PLUGIN_CACHE_PATH');
18+
}
19+
20+
public function testReturnsDefaultPathIfEnvNotSet(): void
21+
{
22+
$path = CacheDirectoryProvider::getCacheLocation();
23+
24+
$this->assertStringEndsWith('/cache', $path);
25+
$this->assertFileExists($path);
26+
}
27+
28+
public function testReturnsCustomPathFromEnv(): void
29+
{
30+
$custom = sys_get_temp_dir() . '/psalm-laravel-stubs-test';
31+
putenv("LARAVEL_PLUGIN_CACHE_PATH={$custom}");
32+
33+
$this->assertSame($custom, CacheDirectoryProvider::getCacheLocation());
34+
}
35+
}

0 commit comments

Comments
 (0)