Skip to content

Commit

Permalink
Chop PHP extension when passed to make commands (#51842)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary authored Jun 19, 2024
1 parent e18596e commit 9619f56
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Illuminate/Console/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,13 @@ protected function sortImports($stub)
*/
protected function getNameInput()
{
return trim($this->argument('name'));
$name = trim($this->argument('name'));

if (Str::endsWith($name, '.php')) {
return Str::substr($name, 0, -4);
}

return $name;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/Integration/Console/GeneratorCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@

namespace Illuminate\Tests\Integration\Console;

use Orchestra\Testbench\Concerns\InteractsWithPublishedFiles;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class GeneratorCommandTest extends TestCase
{
use InteractsWithPublishedFiles;

protected $files = [
'app/Console/Commands/FooCommand.php',
];

public function testItChopsPhpExtension()
{
$this->artisan('make:command', ['name' => 'FooCommand.php'])
->assertExitCode(0);

$this->assertFilenameExists('app/Console/Commands/FooCommand.php');
}

#[DataProvider('reservedNamesDataProvider')]
public function testItCannotGenerateClassUsingReservedName($given)
{
Expand Down

0 comments on commit 9619f56

Please sign in to comment.