CreateStoreTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Tests\Services\StoreService;
  3. use App\OracleDOCASNDetail;
  4. use App\OracleDOCASNHeader;
  5. use App\Services\CommodityService;
  6. use App\Services\StoreService;
  7. use Carbon\Carbon;
  8. use Illuminate\Foundation\Testing\RefreshDatabase;
  9. use Illuminate\Support\Facades\DB;
  10. use Tests\TestCase;
  11. class CreateStoreTest extends TestCase
  12. {
  13. // use RefreshDatabase;
  14. /** @var StoreService $service */
  15. public $service;
  16. public $asnHeaders;
  17. public $stores;
  18. public function setUp(): void
  19. {
  20. parent::setUp(); // TODO: Change the autogenerated stub
  21. $startDate = \Illuminate\Support\Carbon::now()->subSeconds(30);
  22. $this->service=app(StoreService::class);
  23. $this->asnHeaders=OracleDOCASNHeader::query()
  24. ->with(['asnType', 'asnStatus'])
  25. ->where('addTime', '>=', $startDate)
  26. ->get();
  27. }
  28. public function testCreateStore(){
  29. if (!$this->asnHeaders) return null;
  30. $this->service->createStore($this->asnHeaders);
  31. $this->stores=$this->service->getByWms($this->asnHeaders);
  32. $this->assertNotnull($this->stores);
  33. $this->assertNotNull($this->asnHeaders);
  34. }
  35. public function tearDown(): void
  36. {
  37. $storeIds=[];
  38. foreach ($this->stores as $store){
  39. array_push($storeIds,$store->id);
  40. }
  41. $asnDetails=OracleDOCASNDetail::query()->whereIn('asnno',data_get($this->asnHeaders,'*.asnno'))->get();
  42. $maps = [];
  43. foreach ($asnDetails as $asnDetail) {
  44. $value = [
  45. 'owner_code' => $asnDetail->customerid,
  46. 'sku' => $asnDetail->sku,
  47. ];
  48. $maps[json_encode($value)] = $value;
  49. }
  50. /** CommodityService $commodityService */
  51. $commodityService=app(CommodityService::class);
  52. $commodities=$commodityService->getCommoditiesByMaps($maps);
  53. $commodity_ids=[];
  54. foreach ($commodities as $commodity){
  55. array_push($commodity_ids,$commodity->id);
  56. }
  57. DB::table('commodities')->whereIn('id',$commodity_ids)->delete();
  58. DB::table('stores')->whereIn('asn_code',data_get($this->asnHeaders,'*.asnno'))->delete();
  59. DB::table('store_items')->whereIn('store_id',$storeIds)->delete();
  60. cache()->flush();
  61. parent::tearDown(); // TODO: Change the autogenerated stub
  62. }
  63. }