ajun 5 лет назад
Родитель
Сommit
deab689740

+ 90 - 0
tests/Services/CommodityService/GetCommodityByOwnerCodeAndSKUTest.php

@@ -0,0 +1,90 @@
+<?php
+
+namespace Tests\Feature\Services\CommodityService;
+
+use App\Commodity;
+use App\OracleBasSKU;
+use App\Owner;
+use App\Services\CommodityService;
+use App\Services\OracleBasSkuService;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Tests\TestCase;
+
+class GetCommodityByOwnerCodeAndSKUTest extends TestCase
+{
+    use RefreshDatabase;
+
+    /**
+     * @var CommodityService $service
+     */
+    private $service;
+    private $data = [];
+
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->service = app('CommodityService');
+        $owner =  factory(Owner::class)->create();
+        $basSKU = factory(OracleBasSKU::class)->make(['customerid'=>$owner->code]);
+        $this->data['owner'] = $owner;
+        $this->data['basSKU'] = $basSKU;
+        $this->data['commodity1'] = factory(Commodity::class)->create([
+            'owner_id' => $this->data['owner']['id'] ?? '',
+            'sku' => $this->data['basSKU']['sku'],
+            'name' =>$this->data['basSKU']['descr_c'],
+            'length' =>$this->data['basSKU']['skulength'],
+            'width' => $this->data['basSKU']['skuwidth'],
+            'height' => $this->data['basSKU']['skuhigh'],
+            'volumn' => $this->data['basSKU']['cube']
+        ]);
+        $this->mock(OracleBasSkuService::class,function($mock)use($basSKU){
+            $mock->shouldReceive('first')->andReturn($basSKU);
+        });
+
+    }
+
+    /**
+     * @test
+     */
+    public function getCommodityByOwnerCodeAndSKU()
+    {
+        $owner_code = $this->data['owner']['code'];
+        $sku = $this->data['basSKU']['sku'];
+        $commodity = $this->service->getCommodityByOwnerCodeAndSKU($owner_code,$sku);
+        $this->data['commodity'] = $commodity;
+        $this->assertEquals($commodity['owner_id'],$this->data['owner']['id']);
+        $this->assertEquals($commodity['sku'],$this->data['basSKU']['sku']);
+        $this->assertEquals($commodity['name'],$this->data['basSKU']['descr_c']);
+        $this->assertEquals($commodity['length'],$this->data['basSKU']['skulength']);
+        $this->assertEquals($commodity['width'],$this->data['basSKU']['skuwidth']);
+        $this->assertEquals($commodity['height'],$this->data['basSKU']['skuhigh']);
+        $this->assertEquals($commodity['volumn'],$this->data['basSKU']['cube']);
+    }
+
+    /**
+     * @test
+     */
+    public function commodityIsNotExist()
+    {
+        $this->data['commodity1']->delete();
+        $owner_code = $this->data['owner']['code'];
+        $sku = $this->data['basSKU']['sku'];
+        $commodity = $this->service->getCommodityByOwnerCodeAndSKU($owner_code,$sku);
+        $this->assertNotNull($commodity->owner_id);
+        $this->assertEquals($commodity['owner_id'],$this->data['owner']['id']);
+        $this->assertEquals($commodity['sku'],$this->data['basSKU']['sku']);
+        $this->assertEquals($commodity['name'],$this->data['basSKU']['descr_c']);
+        $this->assertEquals($commodity['length'],$this->data['basSKU']['skulength']);
+        $this->assertEquals($commodity['width'],$this->data['basSKU']['skuwidth']);
+        $this->assertEquals($commodity['height'],$this->data['basSKU']['skuhigh']);
+        $this->assertEquals($commodity['volumn'],$this->data['basSKU']['cube']);
+    }
+
+    public function tearDown(): void
+    {
+        $this->data['owner']->delete();
+        $this->data['commodity1']->delete();
+        if(isset($this->data['commodity1']))$this->data['commodity1']->delete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 53 - 0
tests/Services/CommodityService/GetParamsByBasSKUTest.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace Tests\Services\CommodityService;
+
+use App\Commodity;
+use App\OracleBasSKU;
+use App\Owner;
+use App\Services\CommodityService;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Illuminate\Foundation\Testing\WithFaker;
+use Tests\TestCase;
+
+class GetParamsByBasSKUTest extends TestCase
+{
+    use RefreshDatabase;
+    /** @var CommodityService $service */
+    private $service;
+    private $data = [];
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        cache()->flush();
+        $this->service = app('CommodityService');
+        $owner =  factory(Owner::class)->create();
+        $basSKU = factory(OracleBasSKU::class)->make(['customerid'=>$owner->code]);
+        $this->data['owner'] = $owner;
+        $this->data['basSKU'] = $basSKU;
+    }
+
+    /**
+     * @test
+     */
+    public function getParamsByBasSKU()
+    {
+        $created_param = $this->service->getParamsByBasSku($this->data['basSKU']);
+        $this->assertNotNull($created_param['owner_id']);
+        $this->assertEquals($created_param['owner_id'],$this->data['owner']['id']);
+        $this->assertEquals($created_param['sku'],$this->data['basSKU']['sku']);
+        $this->assertEquals($created_param['name'],$this->data['basSKU']['descr_c']);
+        $this->assertEquals($created_param['length'],$this->data['basSKU']['skulength']);
+        $this->assertEquals($created_param['width'],$this->data['basSKU']['skuwidth']);
+        $this->assertEquals($created_param['height'],$this->data['basSKU']['skuhigh']);
+        $this->assertEquals($created_param['volumn'],$this->data['basSKU']['cube']);
+    }
+
+
+
+    public function tearDown(): void
+    {
+        $this->data['owner']->delete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}

+ 62 - 0
tests/Services/OwnerService/GetOwnerByCodeTest.php

@@ -0,0 +1,62 @@
+<?php
+
+namespace Tests\Services\OwnerService;
+
+use App\OracleBasCustomer;
+use App\Owner;
+use App\Services\OwnerService;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Illuminate\Foundation\Testing\WithFaker;
+use Tests\TestCase;
+
+class GetOwnerByCodeTest extends TestCase
+{
+    use RefreshDatabase;
+
+    /** @var OwnerService $service */
+    private $service;
+    private $data = [];
+
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        cache()->flush();
+        $basCustomer = factory(OracleBasCustomer::class)->make([]);
+        $this->data['owner'] = factory(Owner::class)->create();
+        $this->data['basCustomer'] = $basCustomer;
+        $this->service = app('OwnerService');
+        $this->mock('OracleBasCustomerService',function ($mock)use($basCustomer){
+            $mock->shouldReceive('first')->andReturn($basCustomer);
+        });
+    }
+
+    /**
+     * @test
+     */
+    public function getOwnerByCode()
+    {
+        $owner = $this->service->getOwnerByCode($this->data['owner']['code']);
+        $this->assertEquals($owner->id,$this->data['owner']['id']);
+        $this->assertEquals($owner->name,$this->data['owner']['name']);
+    }
+
+    /**
+     * @test
+     */
+    public function ownerIsNotExist()
+    {
+        $this->data['owner']->delete();
+        $owner = $this->service->getOwnerByCode($this->data['owner']['code']);
+        $this->assertEquals($owner->code,$this->data['basCustomer']['customerid']);
+        $this->assertEquals($owner->name,$this->data['basCustomer']['descr_c']);
+        $this->data['owner']= $owner;
+
+    }
+
+    public function tearDown(): void
+    {
+        cache()->flush();
+        $this->data['owner']->delete();
+        parent::tearDown(); // TODO: Change the autogenerated stub
+    }
+}