Skip to content

Commit

Permalink
Update test generation command.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Nov 29, 2016
1 parent 481f760 commit de9e03d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
16 changes: 13 additions & 3 deletions src/Illuminate/Console/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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;
Expand Down Expand Up @@ -164,7 +164,7 @@ protected function replaceNamespace(&$stub, $name)
);

$stub = str_replace(
'DummyRootNamespace', $this->laravel->getNamespace(), $stub
'DummyRootNamespace', $this->rootNamespace(), $stub
);

return $this;
Expand Down Expand Up @@ -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.
*
Expand Down
28 changes: 23 additions & 5 deletions src/Illuminate/Foundation/Console/TestMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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';
}
}

/**
Expand All @@ -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';
}

/**
Expand All @@ -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';
}
}
3 changes: 3 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/test.stub
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace DummyNamespace;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
Expand Down
20 changes: 20 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/unit-test.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace DummyNamespace;

use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class DummyClass extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
$this->assertTrue(true);
}
}

0 comments on commit de9e03d

Please sign in to comment.