diff --git a/src/NewCommand.php b/src/NewCommand.php index 5d62121..4a13b2b 100644 --- a/src/NewCommand.php +++ b/src/NewCommand.php @@ -159,7 +159,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->validateDatabaseOption($input); $this->validateStackOption($input); - $name = $input->getArgument('name'); + $name = mb_rtrim($input->getArgument('name'), '/\\'); $directory = $this->getInstallationDirectory($name); @@ -810,7 +810,7 @@ protected function generateAppUrl($name) */ protected function getTld() { - return $this->runOnValetOrHerd('tld') ?? 'test'; + return $this->runOnValetOrHerd('tld') ?: 'test'; } /** diff --git a/tests/NewCommandTest.php b/tests/NewCommandTest.php index 2020305..222a273 100644 --- a/tests/NewCommandTest.php +++ b/tests/NewCommandTest.php @@ -34,6 +34,32 @@ public function test_it_can_scaffold_a_new_laravel_app() $this->assertFileExists($scaffoldDirectory.'/.env'); } + public function test_it_can_chops_trailing_slash_from_name() + { + $scaffoldDirectoryName = 'tests-output/trailing/'; + $scaffoldDirectory = __DIR__.'/../'.$scaffoldDirectoryName; + + if (file_exists($scaffoldDirectory)) { + if (PHP_OS_FAMILY == 'Windows') { + exec("rd /s /q \"$scaffoldDirectory\""); + } else { + exec("rm -rf \"$scaffoldDirectory\""); + } + } + + $app = new Application('Laravel Installer'); + $app->add(new NewCommand); + + $tester = new CommandTester($app->find('new')); + + $statusCode = $tester->execute(['name' => $scaffoldDirectoryName], ['interactive' => false]); + + $this->assertSame(0, $statusCode); + $this->assertDirectoryExists($scaffoldDirectory.'/vendor'); + $this->assertFileExists($scaffoldDirectory.'/.env'); + $this->assertStringContainsStringIgnoringLineEndings('APP_URL=http://tests-output/trailing.test', file_get_contents($scaffoldDirectory.'/.env')); + } + public function test_on_at_least_laravel_11() { $command = new NewCommand;