ソースを参照

海柔测试boxes

LD 5 年 前
コミット
363ff5f3ed

+ 1 - 3
app/Console/Commands/MakeTestCommand.php

@@ -56,9 +56,7 @@ class MakeTestCommand extends \Illuminate\Foundation\Console\TestMakeCommand
     }
     protected function getModelNamePlural()
     {
-        $modelName=preg_replace('/s$/','ses',lcfirst($this->getModelName()));
-        $modelName=preg_replace('/ch$/','ches',$modelName);
-        $modelName=preg_replace('/sh$/','shes',$modelName);
+        $modelName=preg_replace('/(s|x|ch|sh)$/','ses',lcfirst($this->getModelName()));
         $modelName=preg_replace('/y$/','ies',$modelName);
         $modelName=preg_replace('/[cC]hild$/','children',$modelName);
         if(preg_match('/[cC]hildren$/',$modelName)==0){

+ 38 - 0
tests/Services/BatchService/AssignTasksTest.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace Tests\Services\BatchService;
+use App\Services\BatchService;
+use Tests\TestCase;
+use App\Batch;
+use App\Traits\TestMockSubServices;
+
+class AssignTasksTest extends TestCase
+{
+    use TestMockSubServices;
+    /** @var BatchService $service */
+    public $service;
+    private $data;
+    private $amount=2;
+    function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app('BatchService');
+        $this->data['Batches']
+            = factory(Batch::class, $this->amount)
+            ->create();
+    }
+
+    public function testReturned()
+    {
+        $this->service->assignTasks($this->data['Batches']);
+        $this->assertTrue(true);
+    }
+
+    function tearDown(): void
+    {
+        Batch::query()
+            ->whereIn('id',data_get($this->data['Batches'],'*.id')??[])
+            ->delete();
+        parent::tearDown();
+    }
+}

+ 71 - 0
tests/Services/StationTaskMaterialBoxService/CreateByBatchesTest.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace Tests\Services\StationTaskMaterialBoxService;
+use App\Batch;
+use App\Order;
+use App\OrderCommodity;
+use App\Services\StationTaskMaterialBoxService;
+use Tests\TestCase;
+use App\StationTaskMaterialBox;
+use App\Traits\TestMockSubServices;
+
+class CreateByBatchesTest extends TestCase
+{
+    use TestMockSubServices;
+    /** @var StationTaskMaterialBoxService $service */
+    public $service;
+    private $data;
+    private $batchAmount=2;
+    private $orderAmount=2;
+    private $materialBoxAmount=2;
+    function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app('StationTaskMaterialBoxService');
+        $this->data['batches']
+            = factory(Batch::class, $this->batchAmount)
+            ->create();
+        $this->data['orders']
+            = factory(Order::class, $this->orderAmount)
+            ->create([
+                'batch_id'=>(function(){
+                    if(!isset($this->data['i_batch_id_orders'])){
+                        $this->data['i_batch_id_orders']=$this->batchAmount;
+                    }
+                    $this->data['i_batch_id_orders']++;
+                    if($this->data['i_batch_id_orders']>=$this->batchAmount)$this->data['i_batch_id_orders']=0;
+                    return $this->data['batches'][$this->data['i_batch_id_orders']];
+                })()
+            ]);
+        $this->data['stationTaskMaterialBoxes']
+            = factory(StationTaskMaterialBox::class, $this->materialBoxAmount)
+            ->create();
+        $this->data['orderCommodities']
+            = factory(OrderCommodity::class, $this->materialBoxAmount)
+            ->create([
+                'order_id'=>(function(){
+                    if(!isset($this->data['i_order_id_orderCommodities'])){
+                        $this->data['i_order_id_orderCommodities']=$this->batchAmount;
+                    }
+                    $this->data['i_order_id_orderCommodities']++;
+                    if($this->data['i_order_id_orderCommodities']>=$this->batchAmount)$this->data['i_order_id_orderCommodities']=0;
+                    return $this->data['orders'][$this->data['i_order_id_orderCommodities']];
+                })(),
+                'location'=>
+            ]);
+    }
+
+    public function testReturned()
+    {
+        $this->service->createByBatches();
+        $this->assertTrue(true);
+    }
+
+    function tearDown(): void
+    {
+        StationTaskMaterialBox::query()
+            ->whereIn('id',data_get($this->data['stationTaskMaterialBoxes'],'*.id')??[])
+            ->delete();
+        parent::tearDown();
+    }
+}