|
|
@@ -0,0 +1,90 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace App\Console\Commands;
|
|
|
+
|
|
|
+
|
|
|
+use Illuminate\Filesystem\Filesystem;
|
|
|
+use Symfony\Component\Console\Input\InputArgument;
|
|
|
+
|
|
|
+class TestMakeCommand extends \Illuminate\Foundation\Console\TestMakeCommand
|
|
|
+{
|
|
|
+ protected $signature = 'make:test {name : The name of the class}
|
|
|
+ {--unit : Create a unit test}
|
|
|
+ {--controller : Create a controller test}
|
|
|
+ {--controllers : Create a controllers test}
|
|
|
+ {--service : Create a service test}
|
|
|
+ {--services : Create a services test}
|
|
|
+ ';
|
|
|
+ protected function getDefaultNamespace($rootNamespace)
|
|
|
+ {
|
|
|
+ if ($this->option('controller')
|
|
|
+ ||$this->option('controllers')) {
|
|
|
+ return $rootNamespace.'\Controllers';
|
|
|
+ }
|
|
|
+ if ($this->option('services')
|
|
|
+ ||$this->option('service')) {
|
|
|
+ return $rootNamespace.'\Services\\'
|
|
|
+ .ucfirst($this->getServiceName())
|
|
|
+ ;
|
|
|
+ }
|
|
|
+ if ($this->option('unit')) {
|
|
|
+ return $rootNamespace.'\Unit';
|
|
|
+ } else {
|
|
|
+ return $rootNamespace.'\Feature';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getNameInput()
|
|
|
+ {
|
|
|
+ $input= trim($this->argument('name'));
|
|
|
+ $inputs = explode(':', $input);
|
|
|
+ return $inputs[1]
|
|
|
+ ?$this->getMethodName()
|
|
|
+ :$inputs[0]
|
|
|
+ ;
|
|
|
+ }
|
|
|
+ protected function getServiceName()
|
|
|
+ {
|
|
|
+ $input= trim($this->argument('name'));
|
|
|
+ return explode(':',$input)[0];
|
|
|
+ }
|
|
|
+ protected function getMethodName()
|
|
|
+ {
|
|
|
+ $input= trim($this->argument('name'));
|
|
|
+ return '\Test'.ucfirst(explode(':',$input)[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getStub()
|
|
|
+ {
|
|
|
+ if ($this->option('controller')
|
|
|
+ ||$this->option('controllers')) {
|
|
|
+ return __DIR__.('/stubs/test.controller.stub');
|
|
|
+ }
|
|
|
+ if ($this->option('services')
|
|
|
+ ||$this->option('service')) {
|
|
|
+ return __DIR__.('/stubs/test.service.stub');
|
|
|
+ }
|
|
|
+ return $this->option('unit')
|
|
|
+ ? $this->resolveStubPath('/stubs/test.unit.stub')
|
|
|
+ : $this->resolveStubPath('/stubs/test.stub');
|
|
|
+ }
|
|
|
+ protected function getArguments()
|
|
|
+ {
|
|
|
+ $args=parent::getArguments();
|
|
|
+ $args[]=['xx', InputArgument::REQUIRED, 'xx'];
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function buildClass($name)
|
|
|
+ {
|
|
|
+ $stub = $this->files->get($this->getStub());
|
|
|
+
|
|
|
+ return $this->replaceNamespace($stub, $name)->replaceClass($stub, $name);
|
|
|
+ }
|
|
|
+ protected function replaceClass($stub, $name)
|
|
|
+ {
|
|
|
+ $class = str_replace($this->getNamespace($name).'\\', '', $name);
|
|
|
+
|
|
|
+ return str_replace(['DummyClass', '{{ class }}', '{{class}}'], $class, $stub);
|
|
|
+ }
|
|
|
+}
|