Browse Source

Added Model class

tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
3b2a9ceda2
  1. 39
      src/CrudMake.php
  2. 25
      src/ServiceProvider.php
  3. 30
      tests/CrudMakeCommandTest.php

39
src/CrudMake.php

@ -0,0 +1,39 @@
<?php
namespace Luthfi\CrudGenerator;
use Illuminate\Support\Str;
use Illuminate\Console\Command;
class CrudMake extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:crud {name}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create simple Laravel CRUD files of given model name.';
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$model = $this->argument('name');
$pluralModel = str_plural($model);
$this->callSilent('make:model', ['name' => $model]);
$this->info($model.' model generated.');
$this->info('CRUD files generated successfully!');
}
}

25
src/ServiceProvider.php

@ -0,0 +1,25 @@
<?php
namespace Luthfi\CrudGenerator;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
/**
* Crud Generator Service Provider Class.
*/
class ServiceProvider extends BaseServiceProvider
{
public function register()
{
if ($this->app->runningInConsole()) {
$this->commands([
CrudMake::class,
]);
}
}
public function boot()
{
}
}

30
tests/CrudMakeCommandTest.php

@ -0,0 +1,30 @@
<?php
use Orchestra\Testbench\TestCase;
class CrudMakeCommandTest extends TestCase
{
protected function getPackageProviders($app)
{
return ['Luthfi\CrudGenerator\ServiceProvider'];
}
/** @test */
public function it_can_generate_simple_crud_files()
{
$this->artisan('make:crud', ['name' => 'Test', '--no-interaction' => true]);
$this->assertFileExists(app_path('Test.php'));
// $this->assertFileExists(app_path('Http/Controllers/TestsController.php'));
// $this->assertFileExists(resource_path('views/tests/index.blade.php'));
// $this->assertFileExists(resource_path('views/tests/forms.blade.php'));
// $this->assertFileExists(base_path('tests/Feature/ManageTestsTest.php'));
// $this->assertFileExists(base_path('tests/Unit/Models/TestTest.php'));
exec('rm '.app_path('Test.php'));
// exec('rm -r '.app_path('Http/Controllers'));
// exec('rm -r '.resource_path('views/tests'));
// exec('rm '.base_path('tests/Feature/ManageTestsTest.php'));
// exec('rm '.base_path('tests/Unit/ModelsTestTest.php'));
}
}
Loading…
Cancel
Save