3 changed files with 92 additions and 69 deletions
-
73src/CrudMake.php
-
60src/Generators/FeatureTestGenerator.php
-
28src/Generators/ModelTestGenerator.php
@ -0,0 +1,60 @@ |
|||
<?php |
|||
|
|||
namespace Luthfi\CrudGenerator\Generators; |
|||
|
|||
/** |
|||
* Feature Test Generator Class |
|||
*/ |
|||
class FeatureTestGenerator extends BaseGenerator |
|||
{ |
|||
/** |
|||
* {@inheritDoc} |
|||
*/ |
|||
public function generate() |
|||
{ |
|||
$this->createBrowserKitBaseTestClass(); |
|||
|
|||
$featureTestPath = $this->makeDirectory(base_path('tests/Feature')); |
|||
$this->generateFile("{$featureTestPath}/Manage{$this->modelNames['plural_model_name']}Test.php", $this->getContent()); |
|||
$this->command->info('Manage'.$this->modelNames['plural_model_name'].'Test generated.'); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* {@inheritDoc} |
|||
*/ |
|||
protected function getContent() |
|||
{ |
|||
$stub = $this->files->get(__DIR__.'/../stubs/test-feature.stub'); |
|||
return $this->replaceStubString($stub); |
|||
} |
|||
|
|||
/** |
|||
* Generate BrowserKitTest class for BaseTestCase |
|||
* |
|||
* @return void |
|||
*/ |
|||
private function createBrowserKitBaseTestClass() |
|||
{ |
|||
$testsPath = base_path('tests'); |
|||
if (! $this->files->isDirectory($testsPath)) { |
|||
$this->files->makeDirectory($testsPath, 0777, true, true); |
|||
} |
|||
|
|||
if (! $this->files->exists($testsPath.'/BrowserKitTest.php')) { |
|||
$this->generateFile($testsPath.'/BrowserKitTest.php', $this->getBrowserKitBaseTestContent()); |
|||
|
|||
$this->command->info('BrowserKitTest generated.'); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Get BrowserKitBaseTest class file content |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getBrowserKitBaseTestContent() |
|||
{ |
|||
return $this->files->get(__DIR__.'/../stubs/test-browserkit-base-class.stub'); |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?php |
|||
|
|||
namespace Luthfi\CrudGenerator\Generators; |
|||
|
|||
/** |
|||
* Model Test Generator Class |
|||
*/ |
|||
class ModelTestGenerator extends BaseGenerator |
|||
{ |
|||
/** |
|||
* {@inheritDoc} |
|||
*/ |
|||
public function generate() |
|||
{ |
|||
$unitTestPath = $this->makeDirectory(base_path('tests/Unit/Models')); |
|||
$this->generateFile("{$unitTestPath}/{$this->modelNames['model_name']}Test.php", $this->getContent()); |
|||
$this->command->info($this->modelNames['model_name'].'Test (model) generated.'); |
|||
} |
|||
|
|||
/** |
|||
* {@inheritDoc} |
|||
*/ |
|||
protected function getContent() |
|||
{ |
|||
$stub = $this->files->get(__DIR__.'/../stubs/test-unit.stub'); |
|||
return $this->replaceStubString($stub); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue