Kaynağa Gözat

test make命令修改

LD 5 yıl önce
ebeveyn
işleme
d4169f97c1

+ 13 - 0
app/Console/Commands/TestMakeCommand.php

@@ -54,6 +54,18 @@ class TestMakeCommand extends \Illuminate\Foundation\Console\TestMakeCommand
         $input= trim($this->argument('name'));
         return str_replace('Service','',(explode(':',$input)[0]));
     }
+    protected function getModelNamePlural()
+    {
+        $modelName=preg_replace('/s$/','$ses',$this->getModelName());
+        $modelName=preg_replace('/ch$/','$ches',$modelName);
+        $modelName=preg_replace('/sh$/','$shes',$modelName);
+        $modelName=preg_replace('/y$/','ies',$modelName);
+        $modelName=preg_replace('/[cC]hild$/','children',$modelName);
+        if(preg_match('/[cC]hildren$/',$modelName)==0){
+            $modelName=preg_replace('/([^s])$/','$1s',$modelName);
+        }
+        return $modelName;
+    }
     protected function getMethodName()
     {
         $input= trim($this->argument('name'));
@@ -82,6 +94,7 @@ class TestMakeCommand extends \Illuminate\Foundation\Console\TestMakeCommand
         $stub = str_replace(['{{ serviceName }}', '{{serviceName}}'], $this->getServiceName(), $stub);
         $stub = str_replace(['{{ modelName }}', '{{modelName}}'], $this->getModelName(), $stub);
         $stub = str_replace(['{{ modelNameUc }}', '{{modelNameUc}}'], ucfirst($this->getModelName()), $stub);
+        $stub = str_replace(['{{ modelNamePlural }}', '{{modelNamePlural}}'], ucfirst($this->getModelNamePlural()), $stub);
 
         return str_replace(['DummyClass', '{{ class }}', '{{class}}'], $class, $stub);
     }

+ 2 - 2
app/Console/Commands/stubs/model.stub

@@ -4,11 +4,11 @@ namespace {{ namespace }};
 
 use Illuminate\Database\Eloquent\Model;
 
-use App\Traits\LogChanging;
+use App\Traits\LogModelChanging;
 
 class {{ class }} extends Model
 {
-    use LogChanging;
+    use LogModelChanging;
 
     //
 }

+ 2 - 2
app/Console/Commands/stubs/test.service.stub

@@ -16,7 +16,7 @@ class {{ class }} extends TestCase
     {
         parent::setUp();
         $this->service = app('{{ serviceName }}');
-        $this->data['{{ modelName }}s']
+        $this->data['{{ modelNamePlural }}']
             = factory({{ modelNameUc }}::class, $this->amount)
             ->create();
     }
@@ -29,7 +29,7 @@ class {{ class }} extends TestCase
     function tearDown(): void
     {
         {{ modelNameUc }}::query()
-            ->whereIn('id',data_get($this->data['{{ modelName }}s'],'*.id')??[])
+            ->whereIn('id',data_get($this->data['{{ modelNamePlural }}'],'*.id')??[])
             ->delete();
         parent::tearDown();
     }

+ 2 - 5
public/t.php

@@ -1,7 +1,4 @@
 <?php
 
-class  Abc{
-function xx(){}
-}
-$a=( Abc );
-var_dump(method_exists($a,'xx'));
+$s = '434211kjk';
+var_dump(preg_match('/434/',$s));