From 3ae313eb92d435167d218683adb0170a0a602723 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 20 Jun 2024 09:35:14 +0700 Subject: [PATCH 1/2] Test application storage path --- .../FoundationApplicationBuilderTest.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/Foundation/FoundationApplicationBuilderTest.php b/tests/Foundation/FoundationApplicationBuilderTest.php index fa69d0692ead..5b98abd933ab 100644 --- a/tests/Foundation/FoundationApplicationBuilderTest.php +++ b/tests/Foundation/FoundationApplicationBuilderTest.php @@ -14,6 +14,8 @@ protected function tearDown(): void unset($_ENV['APP_BASE_PATH']); + unset($_ENV['LARAVEL_STORAGE_PATH'], $_SERVER['LARAVEL_STORAGE_PATH']); + parent::tearDown(); } @@ -41,4 +43,49 @@ public function testBaseDirectoryWithComposer() $this->assertSame(dirname(__DIR__, 2), $app->basePath()); } + + public function testStoragePathWithGlobalEnvVariable() + { + $_ENV['LARAVEL_STORAGE_PATH'] = __DIR__.'/env-storage'; + + $app = Application::configure()->create(); + + $this->assertSame(__DIR__.'/env-storage', $app->storagePath()); + } + + public function testStoragePathWithGlobalServerVariable() + { + $_SERVER['LARAVEL_STORAGE_PATH'] = __DIR__.'/server-storage'; + + $app = Application::configure()->create(); + + $this->assertSame(__DIR__.'/server-storage', $app->storagePath()); + } + + public function testStoragePathPrefersEnvVariable() + { + $_ENV['LARAVEL_STORAGE_PATH'] = __DIR__.'/env-storage'; + $_SERVER['LARAVEL_STORAGE_PATH'] = __DIR__.'/server-storage'; + + $app = Application::configure()->create(); + + $this->assertSame(__DIR__.'/env-storage', $app->storagePath()); + } + + public function testStoragePathBasedOnBasePath() + { + $app = Application::configure()->create(); + $this->assertSame($app->basePath() . DIRECTORY_SEPARATOR . 'storage', $app->storagePath()); + } + + public function testStoragePathCanBeCustomized() + { + $_ENV['LARAVEL_STORAGE_PATH'] = __DIR__.'/env-storage'; + $_SERVER['LARAVEL_STORAGE_PATH'] = __DIR__.'/server-storage'; + + $app = Application::configure()->create(); + $app->useStoragePath(__DIR__.'/custom-storage'); + + $this->assertSame(__DIR__.'/custom-storage', $app->storagePath()); + } } From 5a33fc29c8690079f3111ea9038653dfeb7b411d Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 20 Jun 2024 09:48:48 +0700 Subject: [PATCH 2/2] StyleCI --- tests/Foundation/FoundationApplicationBuilderTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Foundation/FoundationApplicationBuilderTest.php b/tests/Foundation/FoundationApplicationBuilderTest.php index 5b98abd933ab..7d73be6d8fc6 100644 --- a/tests/Foundation/FoundationApplicationBuilderTest.php +++ b/tests/Foundation/FoundationApplicationBuilderTest.php @@ -75,13 +75,12 @@ public function testStoragePathPrefersEnvVariable() public function testStoragePathBasedOnBasePath() { $app = Application::configure()->create(); - $this->assertSame($app->basePath() . DIRECTORY_SEPARATOR . 'storage', $app->storagePath()); + $this->assertSame($app->basePath().DIRECTORY_SEPARATOR.'storage', $app->storagePath()); } public function testStoragePathCanBeCustomized() { $_ENV['LARAVEL_STORAGE_PATH'] = __DIR__.'/env-storage'; - $_SERVER['LARAVEL_STORAGE_PATH'] = __DIR__.'/server-storage'; $app = Application::configure()->create(); $app->useStoragePath(__DIR__.'/custom-storage');