| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace Tests\Services\StoreService;
- use App\OracleDOCASNDetail;
- use App\OracleDOCASNHeader;
- use App\Services\CommodityService;
- use App\Services\StoreService;
- use Carbon\Carbon;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Illuminate\Support\Facades\DB;
- use Tests\TestCase;
- class CreateStoreTest extends TestCase
- {
- // use RefreshDatabase;
- /** @var StoreService $service */
- public $service;
- public $asnHeaders;
- public $stores;
- public function setUp(): void
- {
- parent::setUp(); // TODO: Change the autogenerated stub
- $startDate = \Illuminate\Support\Carbon::now()->subSeconds(30);
- $this->service=app(StoreService::class);
- $this->asnHeaders=OracleDOCASNHeader::query()
- ->with(['asnType', 'asnStatus'])
- ->where('addTime', '>=', $startDate)
- ->get();
- }
- public function testCreateStore(){
- if (!$this->asnHeaders) return null;
- $this->service->createStore($this->asnHeaders);
- $this->stores=$this->service->getByWms($this->asnHeaders);
- $this->assertNotnull($this->stores);
- $this->assertNotNull($this->asnHeaders);
- }
- public function tearDown(): void
- {
- $storeIds=[];
- foreach ($this->stores as $store){
- array_push($storeIds,$store->id);
- }
- $asnDetails=OracleDOCASNDetail::query()->whereIn('asnno',data_get($this->asnHeaders,'*.asnno'))->get();
- $maps = [];
- foreach ($asnDetails as $asnDetail) {
- $value = [
- 'owner_code' => $asnDetail->customerid,
- 'sku' => $asnDetail->sku,
- ];
- $maps[json_encode($value)] = $value;
- }
- /** CommodityService $commodityService */
- $commodityService=app(CommodityService::class);
- $commodities=$commodityService->getCommoditiesByMaps($maps);
- $commodity_ids=[];
- foreach ($commodities as $commodity){
- array_push($commodity_ids,$commodity->id);
- }
- DB::table('commodities')->whereIn('id',$commodity_ids)->delete();
- DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
- DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
- cache()->flush();
- parent::tearDown(); // TODO: Change the autogenerated stub
- }
- }
|