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

[deleted] #382

Closed
wants to merge 2 commits into from
Closed
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
38 changes: 22 additions & 16 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ protected function configure()
->setName('new')
->setDescription('Create a new Laravel application')
->addArgument('name', InputArgument::REQUIRED)
->addOption('dev', null, InputOption::VALUE_NONE, 'Installs the latest "development" release')
->addOption('dev', null, InputOption::VALUE_NONE, 'Installs the latest "development" release. Cannot be used with --target')
->addOption('target', null, InputOption::VALUE_OPTIONAL, 'Installs the specified version of Laravel. Cannot be used with --dev')
->addOption('git', null, InputOption::VALUE_NONE, 'Initialize a Git repository')
->addOption('branch', null, InputOption::VALUE_REQUIRED, 'The branch that should be created for a new repository', $this->defaultBranch())
->addOption('github', null, InputOption::VALUE_OPTIONAL, 'Create a new repository on GitHub', false)
Expand Down Expand Up @@ -190,6 +191,7 @@ protected function ensureExtensionsAreAvailable(InputInterface $input, OutputInt
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->validateDevAndTargetOptions($input);
$this->validateDatabaseOption($input);
$this->validateStackOption($input);

Expand Down Expand Up @@ -382,21 +384,6 @@ protected function configureDefaultDatabaseConnection(string $directory, string
);
}

/**
* Determine if the application is using Laravel 11 or newer.
*
* @param string $directory
* @return bool
*/
public function usingLaravelVersionOrNewer(int $usingVersion, string $directory): bool
{
$version = json_decode(file_get_contents($directory.'/composer.json'), true)['require']['laravel/framework'];
$version = str_replace('^', '', $version);
$version = explode('.', $version)[0];

return $version >= $usingVersion;
}

/**
* Comment the irrelevant database configuration entries for SQLite applications.
*
Expand Down Expand Up @@ -648,6 +635,21 @@ protected function promptForJetstreamOptions(InputInterface $input)
))->each(fn ($option) => $input->setOption($option, true));
}

/**
* Validate the usage of --dev and --target options.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @return void
*
* @throws \InvalidArgumentException
*/
protected function validateDevAndTargetOptions(InputInterface $input)
{
if ($input->getOption('dev') && $input->getOption('target')) {
throw new \InvalidArgumentException('The --dev and --target options cannot be used together. Please specify only one.');
}
}

/**
* Validate the database driver input.
*
Expand Down Expand Up @@ -884,6 +886,10 @@ protected function getVersion(InputInterface $input)
return 'dev-master';
}

if ($input->getOption('target')) {
return $input->getOption('target');
}

return '';
}

Expand Down
13 changes: 0 additions & 13 deletions tests/NewCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,4 @@ public function test_it_can_chops_trailing_slash_from_name()
);
}
}

public function test_on_at_least_laravel_11()
{
$command = new NewCommand;

$onLaravel10 = $command->usingLaravelVersionOrNewer(11, __DIR__.'/fixtures/laravel10');
$onLaravel11 = $command->usingLaravelVersionOrNewer(11, __DIR__.'/fixtures/laravel11');
$onLaravel12 = $command->usingLaravelVersionOrNewer(11, __DIR__.'/fixtures/laravel12');

$this->assertFalse($onLaravel10);
$this->assertTrue($onLaravel11);
$this->assertTrue($onLaravel12);
}
}
Loading