diff --git a/src/Console/Commands/InstallCommand.php b/src/Console/Commands/InstallCommand.php index 1e80a65..c5eafd3 100644 --- a/src/Console/Commands/InstallCommand.php +++ b/src/Console/Commands/InstallCommand.php @@ -795,7 +795,15 @@ protected function resolveModuleSelection(array $available): array protected function createStorageLink(): void { - $this->task('Creating storage link', fn () => $this->runArtisan(['storage:link'])); + if (! $this->task('Creating storage link', fn () => $this->runArtisan(['storage:link']))) { + $this->warnNoStorageLink('php artisan storage:link'); + } + } + + /** The app runs without the link, so the install goes on. */ + public function warnNoStorageLink(string $fix): void + { + $this->warn("No storage link: uploaded files will not show until you run `{$fix}`"); } protected function clearCaches(): void diff --git a/src/Environments/DockerEnvironment.php b/src/Environments/DockerEnvironment.php index 432fae3..6f16208 100644 --- a/src/Environments/DockerEnvironment.php +++ b/src/Environments/DockerEnvironment.php @@ -824,7 +824,9 @@ protected function createStorageLink(InstallCommand $command): void $command->info('Creating storage link...'); // Relative: made in the container, but the host serves the app too (E2E, `artisan serve`), // and an absolute link points at /var/www, which only the container has. - $this->execInContainer($command, ['php', 'artisan', 'storage:link', '--relative']); + if (! $this->execInContainer($command, ['php', 'artisan', 'storage:link', '--relative'])) { + $command->warnNoStorageLink($this->printedArtisan().' storage:link --relative'); + } } protected function printedArtisan(): string diff --git a/tests/Feature/Environments/DockerStorageLinkTest.php b/tests/Feature/Environments/DockerStorageLinkTest.php index c3f521a..5041108 100644 --- a/tests/Feature/Environments/DockerStorageLinkTest.php +++ b/tests/Feature/Environments/DockerStorageLinkTest.php @@ -14,15 +14,22 @@ */ class DockerStorageLinkTest extends TestCase { - public function test_the_storage_link_is_relative_so_the_host_can_follow_it(): void + /** @return string[] The warnings printed. */ + private function link(): array { - Process::fake(); - $command = new class extends TestableInstallCommand { + /** @var string[] */ + public array $warned = []; + public function line($string, $style = null, $verbosity = null): void {} public function info($string, $verbosity = null): void {} + + public function warn($string, $verbosity = null): void + { + $this->warned[] = $string; + } }; $command->fakeOptions = ['path' => sys_get_temp_dir()]; @@ -36,6 +43,26 @@ public function link(InstallCommand $command): void $docker->link($command); + return $command->warned; + } + + public function test_the_storage_link_is_relative_so_the_host_can_follow_it(): void + { + Process::fake(); + + $this->assertSame([], $this->link()); + Process::assertRan(fn ($process) => $process->command === ['docker', 'compose', 'exec', '-T', 'app', 'php', 'artisan', 'storage:link', '--relative']); } + + /** The app runs without it, so the install goes on, but never silently. */ + public function test_a_failed_link_says_what_is_missing_and_how_to_make_it(): void + { + Process::fake(['*' => Process::result(errorOutput: 'symlink(): Permission denied', exitCode: 1)]); + + $this->assertSame( + ['No storage link: uploaded files will not show until you run `docker compose exec app php artisan storage:link --relative`'], + $this->link(), + ); + } } diff --git a/tests/Feature/NativeStorageLinkTest.php b/tests/Feature/NativeStorageLinkTest.php new file mode 100644 index 0000000..c525e80 --- /dev/null +++ b/tests/Feature/NativeStorageLinkTest.php @@ -0,0 +1,53 @@ +assertSame([], $this->link(exitCode: 0)); + $this->assertSame( + ['No storage link: uploaded files will not show until you run `php artisan storage:link`'], + $this->link(exitCode: 1), + ); + } + + /** @return string[] The warnings printed. */ + private function link(int $exitCode): array + { + Process::fake(['*' => Process::result(exitCode: $exitCode)]); + + $command = new class extends TestableInstallCommand + { + /** @var string[] */ + public array $warned = []; + + public function link(): void + { + $this->components = new class + { + public function task(string $label, callable $task): void + { + $task(); + } + }; + + $this->createStorageLink(); + } + + public function warn($string, $verbosity = null): void + { + $this->warned[] = $string; + } + }; + $command->fakeOptions = ['path' => sys_get_temp_dir()]; + $command->link(); + + return $command->warned; + } +}