File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
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+
710final 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}
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+ 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+ }
You can’t perform that action at this time.
0 commit comments