Browse Source

Add full model name modelNames attribute on CrudMake

tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
15fa99dce8
  1. 12
      src/CrudMake.php
  2. 6
      src/stubs/controller.model.stub
  3. 2
      src/stubs/model-factory.stub
  4. 2
      src/stubs/test-feature.stub
  5. 2
      src/stubs/test-unit.stub
  6. 9
      tests/CrudMakeCommandTest.php
  7. 6
      tests/Generators/ControllerGeneratorTest.php
  8. 2
      tests/Generators/FeatureTestGeneratorTest.php
  9. 2
      tests/Generators/ModelFactoryGeneratorTest.php
  10. 2
      tests/Generators/ModelTestGeneratorTest.php
  11. 2
      tests/TestCase.php

12
src/CrudMake.php

@ -26,7 +26,7 @@ class CrudMake extends Command
*
* @var array
*/
public $stubModelNames = ['Masters', 'Master', 'masters', 'master', 'mstrCollections', 'singleMstr'];
public $stubModelNames;
/**
* Construct CrudMake class
@ -37,6 +37,15 @@ class CrudMake extends Command
parent::__construct();
$this->files = $files;
$this->stubModelNames = [
'full_model_name' => 'fullMstr',
'plural_model_name' => 'Masters',
'model_name' => 'Master',
'table_name' => 'masters',
'lang_name' => 'master',
'collection_model_var_name' => 'mstrCollections',
'single_model_var_name' => 'singleMstr',
];
}
/**
@ -91,6 +100,7 @@ class CrudMake extends Command
$plural_model_name = str_plural($model_name);
return $this->modelNames = [
'full_model_name' => 'App\\'.$model_name,
'plural_model_name' => $plural_model_name,
'model_name' => $model_name,
'table_name' => snake_case($plural_model_name),

6
src/stubs/controller.model.stub

@ -2,7 +2,7 @@
namespace App\Http\Controllers;
use App\Master;
use fullMstr;
use Illuminate\Http\Request;
class MastersController extends Controller
@ -48,7 +48,7 @@ class MastersController extends Controller
* Update the specified singleMstr in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Master $singleMstr
* @param \fullMstr $singleMstr
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Master $singleMstr)
@ -68,7 +68,7 @@ class MastersController extends Controller
/**
* Remove the specified singleMstr from storage.
*
* @param \App\Master $singleMstr
* @param \fullMstr $singleMstr
* @return \Illuminate\Http\Response
*/
public function destroy(Master $singleMstr)

2
src/stubs/model-factory.stub

@ -1,6 +1,6 @@
<?php
use App\Master;
use fullMstr;
use Faker\Generator as Faker;
$factory->define(Master::class, function (Faker $faker) {

2
src/stubs/test-feature.stub

@ -2,7 +2,7 @@
namespace Tests\Feature;
use App\Master;
use fullMstr;
use Tests\BrowserKitTest as TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;

2
src/stubs/test-unit.stub

@ -2,7 +2,7 @@
namespace Tests\Unit\Models;
use App\Master;
use fullMstr;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

9
tests/CrudMakeCommandTest.php

@ -13,7 +13,13 @@ class CrudMakeCommandTest extends TestCase
$crudMaker = app(CrudMake::class);
$this->assertEquals([
'Masters', 'Master', 'masters', 'master', 'mstrCollections', 'singleMstr',
'full_model_name' => 'fullMstr',
'plural_model_name' => 'Masters',
'model_name' => 'Master',
'table_name' => 'masters',
'lang_name' => 'master',
'collection_model_var_name' => 'mstrCollections',
'single_model_var_name' => 'singleMstr',
], $crudMaker->stubModelNames);
}
@ -23,6 +29,7 @@ class CrudMakeCommandTest extends TestCase
$crudMaker = app(CrudMake::class);
$this->assertEquals([
'full_model_name' => 'App\Category',
'plural_model_name' => 'Categories',
'model_name' => 'Category',
'table_name' => 'categories',

6
tests/Generators/ControllerGeneratorTest.php

@ -16,7 +16,7 @@ class ControllerGeneratorTest extends TestCase
namespace App\Http\Controllers;
use App\\{$this->model_name};
use {$this->full_model_name};
use Illuminate\Http\Request;
class {$this->plural_model_name}Controller extends Controller
@ -62,7 +62,7 @@ class {$this->plural_model_name}Controller extends Controller
* Update the specified {$this->single_model_var_name} in storage.
*
* @param \Illuminate\Http\Request \$request
* @param \App\\{$this->model_name} \${$this->single_model_var_name}
* @param \\{$this->full_model_name} \${$this->single_model_var_name}
* @return \Illuminate\Http\Response
*/
public function update(Request \$request, {$this->model_name} \${$this->single_model_var_name})
@ -82,7 +82,7 @@ class {$this->plural_model_name}Controller extends Controller
/**
* Remove the specified {$this->single_model_var_name} from storage.
*
* @param \App\\{$this->model_name} \${$this->single_model_var_name}
* @param \\{$this->full_model_name} \${$this->single_model_var_name}
* @return \Illuminate\Http\Response
*/
public function destroy({$this->model_name} \${$this->single_model_var_name})

2
tests/Generators/FeatureTestGeneratorTest.php

@ -53,7 +53,7 @@ abstract class BrowserKitTest extends BaseTestCase
namespace Tests\Feature;
use App\\{$this->model_name};
use {$this->full_model_name};
use Tests\BrowserKitTest as TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;

2
tests/Generators/ModelFactoryGeneratorTest.php

@ -15,7 +15,7 @@ class ModelFactoryGeneratorTest extends TestCase
$this->assertFileExists($modelFactoryPath);
$modelFactoryContent = "<?php
use App\\{$this->model_name};
use {$this->full_model_name};
use Faker\Generator as Faker;
\$factory->define({$this->model_name}::class, function (Faker \$faker) {

2
tests/Generators/ModelTestGeneratorTest.php

@ -16,7 +16,7 @@ class ModelTestGeneratorTest extends TestCase
namespace Tests\Unit\Models;
use App\\{$this->model_name};
use {$this->full_model_name};
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

2
tests/TestCase.php

@ -6,6 +6,7 @@ use Orchestra\Testbench\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
protected $full_model_name;
protected $model_name;
protected $plural_model_name;
protected $table_name;
@ -18,6 +19,7 @@ abstract class TestCase extends BaseTestCase
parent::setUp();
$this->model_name = 'PaymentMethod';
$this->full_model_name = 'App\\'.$this->model_name;
$this->plural_model_name = str_plural($this->model_name);
$this->table_name = snake_case($this->plural_model_name);
$this->lang_name = snake_case($this->model_name);

Loading…
Cancel
Save