From cebf64a4bb4192adcefcf4c458670818eb0f141d Mon Sep 17 00:00:00 2001 From: Wisp X Date: Sun, 6 Mar 2022 21:32:41 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=20BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Strategy.php | 2 +- tests/TestCase.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Models/Strategy.php b/app/Models/Strategy.php index cda7bfac..4a2e50fb 100644 --- a/app/Models/Strategy.php +++ b/app/Models/Strategy.php @@ -66,7 +66,7 @@ class Strategy extends Model $symlink = self::getRootPath($strategy->configs['url']); $target = $strategy->configs['root'] ?: config('filesystems.disks.uploads.root'); if (! is_dir(public_path($symlink))) { - @(new Filesystem())->link($target, $symlink); + (new Filesystem())->link($target, $symlink); } // 是否需要移除旧的符号链接 $url = $strategy->getOriginal('configs')['url'] ?? ''; diff --git a/tests/TestCase.php b/tests/TestCase.php index 7ffd6f0d..b92ec490 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,10 +9,25 @@ abstract class TestCase extends BaseTestCase { use CreatesApplication; + protected array $links = []; + protected function setUp(): void { parent::setUp(); + $this->links = \config('filesystems.links'); $this->seed(InstallSeeder::class); } + + protected function tearDown(): void + { + parent::tearDown(); + + foreach (array_flip($this->links) as $link) { + @unlink($link); + // 因 phpunit 运行时根目录和 env 同级,所以创建的符号链接被放到了根目录 + // 清理根目录生成的符号链接 + @unlink(str_replace('/public', '', $link)); + } + } }