|
|
@@ -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
|
|
|
+ }
|
|
|
+}
|