diff --git a/src/Illuminate/Console/GeneratorCommand.php b/src/Illuminate/Console/GeneratorCommand.php index 67b34ce8697b..07913bd67eac 100644 --- a/src/Illuminate/Console/GeneratorCommand.php +++ b/src/Illuminate/Console/GeneratorCommand.php @@ -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; } /** diff --git a/tests/Integration/Console/GeneratorCommandTest.php b/tests/Integration/Console/GeneratorCommandTest.php index cb8ce75a6818..0709691166c1 100644 --- a/tests/Integration/Console/GeneratorCommandTest.php +++ b/tests/Integration/Console/GeneratorCommandTest.php @@ -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) {