|
|
@@ -0,0 +1,61 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace Tests\Services\CommodityService;
|
|
|
+
|
|
|
+
|
|
|
+use App\Commodity;
|
|
|
+use App\CommodityBarcode;
|
|
|
+use App\OracleBasSKU;
|
|
|
+use App\Owner;
|
|
|
+use App\Services\CommodityService;
|
|
|
+use Tests\TestCase;
|
|
|
+
|
|
|
+class Get_Test extends TestCase
|
|
|
+{
|
|
|
+ /** @var CommodityService $service */
|
|
|
+ private $service;
|
|
|
+ private $data = [];
|
|
|
+ private $owner_id;
|
|
|
+ public function setUp(): void
|
|
|
+ {
|
|
|
+ parent::setUp(); // TODO: Change the autogenerated stub
|
|
|
+ cache()->flush();
|
|
|
+ $this->service = app('CommodityService');
|
|
|
+ $owner = factory(Owner::class)->create();
|
|
|
+ $commodity=factory(Commodity::class)->create(['owner_id'=>$owner->id]);
|
|
|
+ $this->data['owner'] = $owner;
|
|
|
+ $this->data['commodity'] = $commodity;
|
|
|
+ $this->data['basSku']=OracleBasSKU::query()->orderByDesc('edittime')->first();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testGet_OnlyOwnerIds()
|
|
|
+ {
|
|
|
+ $commodities=$this->service->get_([$this->data['commodity']['owner_id']]);
|
|
|
+ $this->assertNotNull($commodities);
|
|
|
+ $this->assertEquals($this->data['commodity']['sku'],$commodities->first()['sku']);
|
|
|
+ }
|
|
|
+ public function testGet_HasOwnerIdsAndSkus()
|
|
|
+ {
|
|
|
+ $commodities=$this->service->get_([$this->data['commodity']['owner_id']],[$this->data['commodity']['sku']]);
|
|
|
+ $this->assertEquals(1,count($commodities));
|
|
|
+ }
|
|
|
+ public function testGet_SyncAndSelect()
|
|
|
+ {
|
|
|
+ if ($this->data['basSku']) $this->assertNotNull($this->data['basSku']);
|
|
|
+ $this->owner_id=Owner::query()->where('code',$this->data['basSku']['customerid'])->value('id');
|
|
|
+ $commodities=$this->service->get_([ $this->owner_id],[$this->data['basSku']['sku']],[],true);
|
|
|
+ $this->assertEquals($this->data['basSku']['sku'],$commodities->first()['sku']);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function tearDown(): void
|
|
|
+ {
|
|
|
+ $this->data['owner']->delete();
|
|
|
+ $this->data['commodity']->delete();
|
|
|
+ $commodity_id=Commodity::query()->where('owner_id',$this->owner_id)->value('id');
|
|
|
+ Commodity::query()->where('id',$commodity_id)->delete();
|
|
|
+ CommodityBarcode::query()->where('commodity_id',$commodity_id)->delete();
|
|
|
+ cache()->flush();
|
|
|
+ parent::tearDown(); // TODO: Change the autogenerated stub
|
|
|
+ }
|
|
|
+}
|