diff --git a/src/Illuminate/Console/GeneratorCommand.php b/src/Illuminate/Console/GeneratorCommand.php index 798a9dc5e137..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 (string) Str::of($this->argument('name'))->trim()->beforeLast('.php'); + $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 e840dfc982cc..f1ab4c9d62e9 100644 --- a/tests/Integration/Console/GeneratorCommandTest.php +++ b/tests/Integration/Console/GeneratorCommandTest.php @@ -13,6 +13,7 @@ class GeneratorCommandTest extends TestCase protected $files = [ 'app/Console/Commands/FooCommand.php', 'resources/views/foo/php.blade.php', + 'tests/Feature/fixtures.php/SomeTest.php', ]; public function testItChopsPhpExtension() @@ -35,6 +36,18 @@ public function testItChopsPhpExtensionFromMakeViewCommands() $this->assertFilenameExists('resources/views/foo/php.blade.php'); } + public function testItOnlyChopsPhpExtensionFromFilename() + { + $this->artisan('make:test', ['name' => 'fixtures.php/SomeTest']) + ->assertExitCode(0); + + $this->assertFilenameExists('tests/Feature/fixtures.php/SomeTest.php'); + + $this->assertFileContains([ + 'class SomeTest extends TestCase', + ], 'tests/Feature/fixtures.php/SomeTest.php'); + } + #[DataProvider('reservedNamesDataProvider')] public function testItCannotGenerateClassUsingReservedName($given) {