Browse Source

Use replace string helpers with Str class

tags/1.3.2^0 1.3.2
Nafies Luthfi 6 years ago
parent
commit
abe7c9cdf9
  1. 11
      src/GeneratorCommand.php
  2. 4
      src/Generators/LangFileGenerator.php
  3. 5
      tests/Generators/LangGeneratorTest.php
  4. 9
      tests/TestCase.php

11
src/GeneratorCommand.php

@ -2,6 +2,7 @@
namespace Luthfi\CrudGenerator;
use Illuminate\Support\Str;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Console\DetectsApplicationNamespace;
@ -61,7 +62,7 @@ class GeneratorCommand extends Command
{
$modelName = is_null($modelName) ? $this->argument('name') : $modelName;
$model_name = ucfirst(class_basename($modelName));
$plural_model_name = str_plural($model_name);
$plural_model_name = Str::plural($model_name);
$modelPath = $this->getModelPath($modelName);
$modelNamespace = $this->getModelNamespace($modelPath);
@ -70,10 +71,10 @@ class GeneratorCommand extends Command
'full_model_name' => $modelNamespace.'\\'.$model_name,
'plural_model_name' => $plural_model_name,
'model_name' => $model_name,
'table_name' => snake_case($plural_model_name),
'lang_name' => snake_case($model_name),
'collection_model_var_name' => camel_case($plural_model_name),
'single_model_var_name' => camel_case($model_name),
'table_name' => Str::snake($plural_model_name),
'lang_name' => Str::snake($model_name),
'collection_model_var_name' => Str::camel($plural_model_name),
'single_model_var_name' => Str::camel($model_name),
'model_path' => $modelPath,
];
}

4
src/Generators/LangFileGenerator.php

@ -2,6 +2,8 @@
namespace Luthfi\CrudGenerator\Generators;
use Illuminate\Support\Str;
/**
* Lang File Generator Class
*/
@ -35,7 +37,7 @@ class LangFileGenerator extends BaseGenerator
$stub = $this->files->get(__DIR__.'/../stubs/resources/lang/en/master.stub');
}
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->modelNames['model_name'])));
$displayModelName = ucwords(str_replace('_', ' ', Str::snake($this->modelNames['model_name'])));
$properLangFileContent = str_replace(
$this->modelNames['model_name'],

5
tests/Generators/LangGeneratorTest.php

@ -3,6 +3,7 @@
namespace Tests\Generators;
use Tests\TestCase;
use Illuminate\Support\Str;
class LangGeneratorTest extends TestCase
{
@ -13,7 +14,7 @@ class LangGeneratorTest extends TestCase
$locale = config('app.locale');
$langPath = resource_path('lang/'.$locale.'/'.$this->lang_name.'.php');
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->model_name)));
$displayModelName = ucwords(str_replace('_', ' ', Str::snake($this->model_name)));
$this->assertFileExists($langPath);
$langFileContent = "<?php
@ -60,7 +61,7 @@ return [
$locale = config('app.locale');
$langPath = resource_path('lang/'.$locale.'/'.$this->lang_name.'.php');
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->model_name)));
$displayModelName = ucwords(str_replace('_', ' ', Str::snake($this->model_name)));
$this->assertFileExists($langPath);
$langFileContent = "<?php

9
tests/TestCase.php

@ -2,6 +2,7 @@
namespace Tests;
use Illuminate\Support\Str;
use Orchestra\Testbench\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
@ -21,10 +22,10 @@ abstract class TestCase extends BaseTestCase
$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);
$this->collection_model_var_name = camel_case($this->plural_model_name);
$this->single_model_var_name = camel_case($this->model_name);
$this->table_name = Str::snake($this->plural_model_name);
$this->lang_name = Str::snake($this->model_name);
$this->collection_model_var_name = Str::camel($this->plural_model_name);
$this->single_model_var_name = Str::camel($this->model_name);
$this->withoutMockingConsoleOutput();
}

Loading…
Cancel
Save