diff --git a/src/Illuminate/Console/GeneratorCommand.php b/src/Illuminate/Console/GeneratorCommand.php index 97d4c49d9da4..5ec728bb259f 100644 --- a/src/Illuminate/Console/GeneratorCommand.php +++ b/src/Illuminate/Console/GeneratorCommand.php @@ -87,7 +87,7 @@ protected function alreadyExists($rawName) */ protected function getPath($name) { - $name = str_replace_first($this->laravel->getNamespace(), '', $name); + $name = str_replace_first($this->rootNamespace(), '', $name); return $this->laravel['path'].'/'.str_replace('\\', '/', $name).'.php'; } @@ -100,7 +100,7 @@ protected function getPath($name) */ protected function parseName($name) { - $rootNamespace = $this->laravel->getNamespace(); + $rootNamespace = $this->rootNamespace(); if (Str::startsWith($name, $rootNamespace)) { return $name; @@ -164,7 +164,7 @@ protected function replaceNamespace(&$stub, $name) ); $stub = str_replace( - 'DummyRootNamespace', $this->laravel->getNamespace(), $stub + 'DummyRootNamespace', $this->rootNamespace(), $stub ); return $this; @@ -205,6 +205,16 @@ protected function getNameInput() return trim($this->argument('name')); } + /** + * Get the root namespace for the class. + * + * @return string + */ + protected function rootNamespace() + { + return $this->laravel->getNamespace(); + } + /** * Get the console command arguments. * diff --git a/src/Illuminate/Foundation/Console/TestMakeCommand.php b/src/Illuminate/Foundation/Console/TestMakeCommand.php index 7f0efe87211f..3c63323043fc 100644 --- a/src/Illuminate/Foundation/Console/TestMakeCommand.php +++ b/src/Illuminate/Foundation/Console/TestMakeCommand.php @@ -11,7 +11,7 @@ class TestMakeCommand extends GeneratorCommand * * @var string */ - protected $name = 'make:test'; + protected $signature = 'make:test {name : The name of the class} {--unit : Create a unit test}'; /** * The console command description. @@ -34,7 +34,11 @@ class TestMakeCommand extends GeneratorCommand */ protected function getStub() { - return __DIR__.'/stubs/test.stub'; + if ($this->option('unit')) { + return __DIR__.'/stubs/unit-test.stub'; + } else { + return __DIR__.'/stubs/test.stub'; + } } /** @@ -45,9 +49,9 @@ protected function getStub() */ protected function getPath($name) { - $name = str_replace($this->laravel->getNamespace(), '', $name); + $name = str_replace_first($this->rootNamespace(), '', $name); - return $this->laravel['path.base'].'/tests/'.str_replace('\\', '/', $name).'.php'; + return $this->laravel->basePath().'/tests'.str_replace('\\', '/', $name).'.php'; } /** @@ -58,6 +62,20 @@ protected function getPath($name) */ protected function getDefaultNamespace($rootNamespace) { - return $rootNamespace; + if ($this->option('unit')) { + return $rootNamespace.'\Unit'; + } else { + return $rootNamespace.'\Feature'; + } + } + + /** + * Get the root namespace for the class. + * + * @return string + */ + protected function rootNamespace() + { + return 'Tests'; } } diff --git a/src/Illuminate/Foundation/Console/stubs/test.stub b/src/Illuminate/Foundation/Console/stubs/test.stub index 4a2858d9d084..dd804dc9a315 100644 --- a/src/Illuminate/Foundation/Console/stubs/test.stub +++ b/src/Illuminate/Foundation/Console/stubs/test.stub @@ -1,5 +1,8 @@ assertTrue(true); + } +}