Skip to content

Commit

Permalink
with some tests on crud and migration error fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthaksavvy committed Sep 21, 2021
1 parent 9833033 commit 99e4f22
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
.editorconfig
.DS_Store
/package
composer.lock
composer.lock
.phpunit.result.cache
8 changes: 6 additions & 2 deletions app/Commands/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Create extends Command
*
* @var string
*/
protected $signature = 'new {name?} {vendor?} {author_name?} {author_email?} {path?}';
protected $signature = 'new {name?} {vendor?} {author_name?} {author_email?} {keywords?} {path?} ';

/**
* The description of the command.
Expand Down Expand Up @@ -133,7 +133,11 @@ protected function setPackageName()
*/
protected function setKeywords()
{
$keywords = $this->ask('Enter keywords (comma separated)');
$keywords = $this->argument('keywords');
if (!$keywords) {
$keywords = $this->ask('Enter keywords (comma separated)');
}

if ($keywords) {
$keywords = str_replace(', ', ',', $keywords);
}
Expand Down
4 changes: 3 additions & 1 deletion app/Commands/Crud/CrudMigrationCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

namespace App\Commands\Crud;

use Illuminate\Filesystem\Filesystem;
use App\Commands\Helpers\PackageDetail;
use Illuminate\Database\Migrations\MigrationCreator as RealMigrationCreator;

class CrudMigrationCreator extends RealMigrationCreator
{
use PackageDetail;

public function __construct()
public function __construct(Filesystem $files)
{
$this->files = $files;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions app/Commands/Helpers/MakeFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ protected function replaceContent()
{
$vendor = cache()->get('vendor');
$packageName = cache()->get('package_name');
$keywords = cache()->get('keywords');
$keywords = cache()->get('keywords');

if(!$keywords) $composerKeywords = '';
else {
if (!$keywords) {
$composerKeywords = '';
} else {
$composerKeywords = PHP_EOL;
$keywords = explode(',', $keywords);
$keywords = explode(',', $keywords);
foreach ($keywords as $keyword) {
$composerKeywords .= "\t\t".'"' . $keyword .'",' . PHP_EOL;
$composerKeywords .= "\t\t" . '"' . $keyword . '",' . PHP_EOL;
}

$composerKeywords .= "\t"; //format keywords array
Expand Down
4 changes: 2 additions & 2 deletions app/Commands/Helpers/PackageDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public function namespaceFromComposer()

protected function getVendor()
{
return str_before($this->namespaceFromComposer(), '\\');
return Str::before($this->namespaceFromComposer(), '\\');
}

protected function getPackageName()
{
return str_replace('\\', '', Str::after($this->namespaceFromComposer(), '\\'));
return Str::replace('\\', '', Str::after($this->namespaceFromComposer(), '\\'));
}

/**
Expand Down
45 changes: 45 additions & 0 deletions tests/Feature/CrudMakeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Support\Facades\Artisan;

class CrudMakeTest extends TestCase
{
public function setUp():void
{
parent::setUp();
Artisan::call('new TestApp Bitfumes Sarthaks sarthak@bitfumes.com laravel,test');
chdir(base_path());
}

public function tearDown():void
{
parent::tearDown();
$path = base_path() . '/package';
// echo shell_exec("rm -r $path");
}

public function test_it_can_create_a_json_file_to_write_crud_structure()
{
Artisan::call('crud:json Test');
$this->isFileExists('crud/Test.json');
}

public function test_it_can_create_a_crud_for_a_json_file()
{
Artisan::call('crud:json Test');
Artisan::call('crud:make crud/Test.json');
$this->isFileExists('src/Test.php');
$this->isFileExists('src/database/factories/TestFactory.php');
$this->isFileExists('src/Http/controllers/TestController.php');
$this->isFileExists('tests/Feature/TestTest.php');
$this->isFileExists('tests/Unit/TestTest.php');
}

public function isFileExists($filename)
{
return $this->assertFileExists(base_path() . '/package/TestApp/' . $filename);
}
}

0 comments on commit 99e4f22

Please sign in to comment.