Browse Source

Generate lang file within locale config

tags/0.1.1^0 0.1.1
Nafies Luthfi 8 years ago
parent
commit
b9a6cc6811
  1. 4
      src/CrudMake.php
  2. 3
      src/Generators/LangFileGenerator.php
  3. 25
      tests/CrudMakeCommandTest.php
  4. 7
      tests/Generators/LangGeneratorTest.php
  5. 7
      tests/TestCase.php

4
src/CrudMake.php

@ -165,6 +165,8 @@ class CrudMake extends Command
*/
public function modelExists()
{
return $this->files->exists(app_path($this->modelNames['model_path'].'/'.$this->modelNames['model_name'].'.php'));
return $this->files->exists(
app_path($this->modelNames['model_path'].'/'.$this->modelNames['model_name'].'.php')
);
}
}

3
src/Generators/LangFileGenerator.php

@ -12,7 +12,8 @@ class LangFileGenerator extends BaseGenerator
*/
public function generate()
{
$langPath = $this->makeDirectory(resource_path('lang/en'));
$locale = config('app.locale');
$langPath = $this->makeDirectory(resource_path('lang/'.$locale));
$this->createAppLangFile($langPath);
$this->generateFile($langPath.'/'.$this->modelNames['lang_name'].'.php', $this->getContent());

25
tests/CrudMakeCommandTest.php

@ -21,7 +21,10 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileExists(resource_path("lang/en/{$this->lang_name}.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileExists(database_path("factories/{$this->model_name}Factory.php"));
$this->assertFileExists(base_path("routes/web.php"));
$this->assertFileExists(app_path("Policies/{$this->model_name}Policy.php"));
@ -45,7 +48,10 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileNotExists(resource_path("views/{$this->table_name}/index.blade.php"));
$this->assertFileNotExists(resource_path("views/{$this->table_name}/forms.blade.php"));
$this->assertFileNotExists(resource_path("lang/en/{$this->lang_name}.php"));
$localeConfig = config('app.locale');
$this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileNotExists(database_path("factories/{$this->model_name}Factory.php"));
$this->assertFileNotExists(base_path("routes/web.php"));
$this->assertFileNotExists(app_path("Policies/{$this->model_name}Policy.php"));
@ -69,7 +75,10 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileNotExists(resource_path("views/problems/index.blade.php"));
$this->assertFileNotExists(resource_path("views/problems/forms.blade.php"));
$this->assertFileNotExists(resource_path("lang/en/problem.php"));
$localeConfig = config('app.locale');
$this->assertFileNotExists(resource_path("lang/{$localeConfig}/{$this->lang_name}.php"));
$this->assertFileNotExists(database_path("factories/ProblemFactory.php"));
$this->assertFileNotExists(app_path("Policies/ProblemPolicy.php"));
$this->assertFileNotExists(base_path("tests/Feature/ManageProblemsTest.php"));
@ -102,7 +111,10 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(resource_path("views/{$tableName}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$tableName}/forms.blade.php"));
$this->assertFileExists(resource_path("lang/en/{$langName}.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php"));
$this->assertFileExists(database_path("factories/{$modelName}Factory.php"));
$this->assertFileExists(app_path("Policies/{$modelName}Policy.php"));
$this->assertFileExists(base_path("tests/Feature/Manage{$pluralModelName}Test.php"));
@ -132,7 +144,10 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(resource_path("views/{$tableName}/index.blade.php"));
$this->assertFileExists(resource_path("views/{$tableName}/forms.blade.php"));
$this->assertFileExists(resource_path("lang/en/{$langName}.php"));
$localeConfig = config('app.locale');
$this->assertFileExists(resource_path("lang/{$localeConfig}/{$langName}.php"));
$this->assertFileExists(database_path("factories/{$modelName}Factory.php"));
$this->assertFileExists(app_path("Policies/{$parentName}/{$modelName}Policy.php"));
$this->assertFileExists(base_path("tests/Feature/Manage{$pluralModelName}Test.php"));

7
tests/Generators/LangGeneratorTest.php

@ -11,7 +11,8 @@ class LangGeneratorTest extends TestCase
{
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
$langPath = resource_path('lang/en/'.$this->lang_name.'.php');
$locale = config('app.locale');
$langPath = resource_path('lang/'.$locale.'/'.$this->lang_name.'.php');
$displayModelName = ucwords(str_replace('_', ' ', snake_case($this->model_name)));
$this->assertFileExists($langPath);
$langFileContent = "<?php
@ -50,7 +51,9 @@ return [
{
$this->artisan('make:crud', ['name' => $this->model_name, '--no-interaction' => true]);
$langPath = resource_path('lang/en/app.php');
$locale = config('app.locale');
$langPath = resource_path('lang/'.$locale.'/app.php');
$this->assertFileExists($langPath);
$appLangContent = "<?php

7
tests/TestCase.php

@ -42,8 +42,11 @@ abstract class TestCase extends BaseTestCase
$this->removeFileOrDir(database_path('migrations'));
$this->removeFileOrDir(database_path('factories'));
$this->removeFileOrDir(resource_path('views/'.$this->table_name));
$this->removeFileOrDir(resource_path("lang/en/app.php"));
$this->removeFileOrDir(resource_path("lang/en/{$this->lang_name}.php"));
$locale = config('app.locale');
$this->removeFileOrDir(resource_path("lang/{$locale}/app.php"));
$this->removeFileOrDir(resource_path("lang/{$locale}/{$this->lang_name}.php"));
$this->removeFileOrDir(base_path('routes'));
$this->removeFileOrDir(app_path('Policies'));
$this->removeFileOrDir(app_path('Providers'));

Loading…
Cancel
Save