Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove any trailing slash from application name #368

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'), '/\\');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks the minimum required PHP version. This function is introduced on PHP 8.4

Copy link
Contributor Author

@jasonmccreary jasonmccreary Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symfony has a "polyfill" which adds native PHP functions like this to older versions. Tests pass for me locally running PHP 8.3 on Mac.

Did you experience an error or just review the code statically and see this function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is safe to be used since Laravel Framework requires ext-mbstring in it's own composer.json

#373 PR will address this further by throwing an exception if it detects PHP doesn't have the required extensions.


$directory = $this->getInstallationDirectory($name);

Expand Down Expand Up @@ -810,7 +810,7 @@ protected function generateAppUrl($name)
*/
protected function getTld()
{
return $this->runOnValetOrHerd('tld') ?? 'test';
return $this->runOnValetOrHerd('tld') ?: 'test';
}

/**
Expand Down
26 changes: 26 additions & 0 deletions tests/NewCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading