瀏覽代碼

临时提交

ajun 5 年之前
父節點
當前提交
20c4d0c4e0

+ 51 - 0
tests/Services/LogisticService/GetLogisticByCodeTest.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace Tests\Services\LogisticService;
+
+use App\Logistic;
+use App\OracleBasCustomer;
+use App\Owner;
+use App\Services\LogisticService;
+use App\Services\OracleBasCustomerService;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Illuminate\Foundation\Testing\WithFaker;
+use Tests\TestCase;
+
+class GetLogisticByCodeTest extends TestCase
+{
+    /** @var LogisticService $service */
+    private $service;
+    private $data = [];
+
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->service = app('OwnerService');
+
+        $owner = factory(Owner::class)->create();
+        $basCustomer = factory(OracleBasCustomer::class)->make(["customer_type"=>'OW',"customerid"=>$owner->code]);
+        $this->data['basCustomers'] = $basCustomer;
+        $this->data['owners'] = $owner;
+        $this->mock('OracleBasCustomerService',function ($mock)use($basCustomer){
+            $mock->shouldReceive('first')->andReturn($basCustomer);
+        });
+    }
+
+    /**
+     * @test
+     */
+    public function getLogisticByCode()
+    {
+        $logistic = $this->service->getLogisticByCode(data_get($this->data['owners'],'*.code'));
+        $this->assertEquals($logistic->id,$this->data['logistic']['id']);
+        $this->assertEquals($logistic->code,$this->data['logistic']['code']);
+        $this->assertEquals($logistic->name,$this->data['logistic']['name']);
+    }
+
+    public function tearDown(): void
+    {
+        cache()->forget('getLogisticByCode_'.$this->data['logistic']['code']);
+        $this->data['logistic']->delete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 12 - 9
tests/Services/LogisticService/GetLogisticByCodesTest.php

@@ -2,8 +2,10 @@
 
 namespace Tests\Services\LogisticService;
 
+use App\Logistic;
 use App\OracleBasCustomer;
 use App\Services\LogisticService;
+use App\Services\OracleBasCustomerService;
 use Illuminate\Foundation\Testing\RefreshDatabase;
 use Tests\TestCase;
 
@@ -19,15 +21,14 @@ class GetLogisticByCodesTest extends TestCase
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $this->service  = app('LogisticService');
-        $baseCustomers = OracleBasCustomer::query()
-            ->selectRaw('Customer_Type,CustomerID,Descr_C')
-            ->where('Customer_Type','CA')
-            ->get();
-
-        $this->data['baseCustomers'] = $baseCustomers;
-        $this->data['codes'] = $baseCustomers->map(function($baseCustomer){
-            return $baseCustomer->customerid;
+        $logistic =  factory(Logistic::class)->create();
+        $OracleBasCustomer = factory(OracleBasCustomer::class)->make(['customer_type' => 'CA','customerid'=>$logistic->code]);
+        $this->mock(OracleBasCustomerService::class,function ($mock)use($OracleBasCustomer){
+            $mock->shouldReceive('first')->andReturn($OracleBasCustomer);
         });
+
+        $this->data['baseCustomers'] = $OracleBasCustomer;
+        $this->data['logistic'] = $logistic;
     }
 
     /**
@@ -51,7 +52,9 @@ class GetLogisticByCodesTest extends TestCase
 
     public function tearDown(): void
     {
-        cache()->flush();
+        foreach ($this->data['baseCustomers'] as $baseCustomer) {
+            cache()->forget('getLogisticByCode_'.$baseCustomer['customerid']);
+        }
         parent::tearDown(); // TODO: Change the autogenerated stub
     }
 }