Skip to content

Commit 9016de8

Browse files
committed
with some tests and migration issue fixed
1 parent dee3704 commit 9016de8

File tree

5 files changed

+38
-25
lines changed

5 files changed

+38
-25
lines changed

app/Commands/Crud/CrudMakeCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class CrudMakeCommand extends Command
1515
*
1616
* @var string
1717
*/
18-
protected $signature = 'crud:make
19-
{file : Get structure of Model and model name as file name}
18+
protected $signature = 'crud:make
19+
{file : Get structure of Model and model name as file name}
2020
{--model : Model name if you want to override json file name}';
2121

2222
/**
@@ -78,8 +78,8 @@ public function modelName()
7878
public function filePath()
7979
{
8080
$file = $this->argument('file');
81-
$file_path = $this->getPath($file);
82-
if (! file_exists($file_path)) {
81+
$file_path = $this->getPath("crud/$file") . '.json';
82+
if (!file_exists($file_path)) {
8383
$this->error('File not found, please give relative path.');
8484
die();
8585
}

app/Commands/Crud/CrudMigrationCreator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function addFieldsToStub($table, $create)
7171
$table->' . "{$field->type}('{$field->name}'$length){$index}{$def}{$nullable};";
7272
// $table->' . $field->type . '(\'' . $field->name . '\');';
7373
}
74-
$to_replace = '$table->bigIncrements(\'id\');';
74+
$to_replace = '$table->id();';
7575
$replace_with = $to_replace . $newLine;
7676
$result = str_replace($to_replace, $replace_with, $stub);
7777
return $result;

app/Commands/Crud/JsonMakeCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public function getStub()
4040

4141
public function getFilename()
4242
{
43-
return ucfirst($this->argument('model_name')) . '.json';
43+
$name = $this->argument('model_name');
44+
$name = explode('.', $name)[0];
45+
return ucfirst($name) . '.json';
4446
}
4547

4648
public function getPath()

tests/Feature/CrudMakeTest.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,12 @@
33
namespace Tests\Feature;
44

55
use Tests\TestCase;
6+
use Tests\RefreshPacker;
67
use Illuminate\Support\Facades\Artisan;
78

89
class CrudMakeTest extends TestCase
910
{
10-
public function setUp():void
11-
{
12-
parent::setUp();
13-
Artisan::call('new TestApp Bitfumes Sarthaks sarthak@bitfumes.com laravel,test');
14-
chdir(base_path());
15-
}
16-
17-
public function tearDown():void
18-
{
19-
parent::tearDown();
20-
$path = base_path() . '/package';
21-
echo shell_exec("rm -r $path");
22-
}
11+
use RefreshPacker;
2312

2413
public function test_it_can_create_a_json_file_to_write_crud_structure()
2514
{
@@ -30,16 +19,11 @@ public function test_it_can_create_a_json_file_to_write_crud_structure()
3019
public function test_it_can_create_a_crud_for_a_json_file()
3120
{
3221
Artisan::call('crud:json Test');
33-
Artisan::call('crud:make crud/Test.json');
22+
Artisan::call('crud:make Test');
3423
$this->isFileExists('src/Test.php');
3524
$this->isFileExists('src/database/factories/TestFactory.php');
3625
$this->isFileExists('src/Http/controllers/TestController.php');
3726
$this->isFileExists('tests/Feature/TestTest.php');
3827
$this->isFileExists('tests/Unit/TestTest.php');
3928
}
40-
41-
public function isFileExists($filename)
42-
{
43-
return $this->assertFileExists(base_path() . '/package/TestApp/' . $filename);
44-
}
4529
}

tests/RefreshPacker.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Illuminate\Support\Facades\Artisan;
6+
7+
trait RefreshPacker
8+
{
9+
public function setUp():void
10+
{
11+
parent::setUp();
12+
Artisan::call('new TestApp Bitfumes Sarthaks sarthak@bitfumes.com laravel,test');
13+
chdir(base_path());
14+
}
15+
16+
public function tearDown():void
17+
{
18+
parent::tearDown();
19+
$path = base_path() . '/package';
20+
echo shell_exec("rm -r $path");
21+
}
22+
23+
public function isFileExists($filename)
24+
{
25+
return $this->assertFileExists(base_path() . '/package/TestApp/' . $filename);
26+
}
27+
}

0 commit comments

Comments
 (0)