File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 44
55namespace Psalm \LaravelPlugin \Providers ;
66
7+ use function getenv ;
8+ use function rtrim ;
9+
10+ use const DIRECTORY_SEPARATOR ;
11+
712final class CacheDirectoryProvider
813{
914 public static function getCacheLocation (): string
1015 {
11- return __DIR__ . '/../../cache ' ;
16+ $ env = getenv ('PSALM_LARAVEL_PLUGIN_CACHE_PATH ' );
17+ if ($ env !== false && $ env !== '' ) {
18+ return rtrim ($ env , DIRECTORY_SEPARATOR );
19+ }
20+
21+ return __DIR__ . DIRECTORY_SEPARATOR . '.. ' . DIRECTORY_SEPARATOR . '.. ' . DIRECTORY_SEPARATOR . 'cache ' ;
1222 }
1323}
Original file line number Diff line number Diff line change 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+ use const DIRECTORY_SEPARATOR ;
14+
15+ final class CacheDirectoryProviderTest extends TestCase
16+ {
17+ protected function tearDown (): void
18+ {
19+ putenv ('PSALM_LARAVEL_PLUGIN_CACHE_PATH ' );
20+ }
21+
22+ public function testReturnsDefaultPathIfEnvNotSet (): void
23+ {
24+ $ path = CacheDirectoryProvider::getCacheLocation ();
25+
26+ $ this ->assertStringEndsWith (DIRECTORY_SEPARATOR . 'cache ' , $ path );
27+ $ this ->assertFileExists ($ path );
28+ }
29+
30+ public function testReturnsCustomPathFromEnv (): void
31+ {
32+ $ custom = sys_get_temp_dir () . '/psalm-laravel-stubs-test ' ;
33+ putenv ("PSALM_LARAVEL_PLUGIN_CACHE_PATH= {$ custom }" );
34+
35+ $ this ->assertSame ($ custom , CacheDirectoryProvider::getCacheLocation ());
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments