Browse Source

Refactor CrudMake Command class and added test stubs

tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
5061ef6c13
  1. 51
      src/CrudMake.php
  2. 21
      src/stubs/test.stub
  3. 20
      src/stubs/unit-test.stub

51
src/CrudMake.php

@ -74,14 +74,14 @@ class CrudMake extends Command
}
$controllerPath = app_path('Http/Controllers/'.$this->pluralModelName.'Controller.php');
$this->files->put($controllerPath, $this->files->get(__DIR__.'/stubs/controller.model.stub'));
$this->files->put($controllerPath, $this->getControllerStub());
$this->info($this->pluralModelName.'Controller generated.');
}
public function generateMigration()
{
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->lowerCasePluralModel.'_table.php');
$this->files->put($migrationFilePath, $this->files->get(__DIR__.'/stubs/migration-create.stub'));
$this->files->put($migrationFilePath, $this->getMigrationStub());
$this->info($this->modelName.' table migration generated.');
}
@ -93,18 +93,57 @@ class CrudMake extends Command
$this->files->makeDirectory($viewPath, 0777, true, true);
}
$this->files->put($viewPath.'/index.blade.php', $this->files->get(__DIR__.'/stubs/view-index.stub'));
$this->files->put($viewPath.'/forms.blade.php', $this->files->get(__DIR__.'/stubs/view-forms.stub'));
$this->files->put($viewPath.'/index.blade.php', $this->getIndexViewStub());
$this->files->put($viewPath.'/forms.blade.php', $this->getFormsViewStub());
$this->info($this->modelName.' view files generated.');
}
public function generateTests()
{
$this->callSilent('make:test', ['name' => 'Manage'.$this->pluralModelName.'Test']);
$featureTestPath = base_path('tests/Feature');
if (! $this->files->isDirectory($featureTestPath)) {
$this->files->makeDirectory($featureTestPath, 0777, true, true);
}
$this->files->put($featureTestPath.'/Manage'.$this->pluralModelName.'Test.php', $this->getFeatureTestStub());
$this->info('Manage'.$this->pluralModelName.'Test generated.');
$this->callSilent('make:test', ['name' => 'Models/'.$this->modelName.'Test', '--unit' => true]);
$unitTestPath = base_path('tests/Unit/Models');
if (! $this->files->isDirectory($unitTestPath)) {
$this->files->makeDirectory($unitTestPath, 0777, true, true);
}
$this->files->put($unitTestPath.'/'.$this->modelName.'Test.php', $this->getUnitTestStub());
$this->info($this->modelName.'Test (model) generated.');
}
public function getControllerStub()
{
return $this->files->get(__DIR__.'/stubs/controller.model.stub');
}
private function getMigrationStub()
{
return $this->files->get(__DIR__.'/stubs/migration-create.stub');
}
public function getIndexViewStub()
{
return $this->files->get(__DIR__.'/stubs/view-index.stub');
}
public function getFormsViewStub()
{
return $this->files->get(__DIR__.'/stubs/view-forms.stub');
}
public function getFeatureTestStub()
{
return $this->files->get(__DIR__.'/stubs/test.stub');
}
public function getUnitTestStub()
{
return $this->files->get(__DIR__.'/stubs/unit-test.stub');
}
}

21
src/stubs/test.stub

@ -0,0 +1,21 @@
<?php
namespace DummyNamespace;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
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);
}
}

20
src/stubs/unit-test.stub

@ -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);
}
}
Loading…
Cancel
Save