GetParamByOrderHeaderTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Tests\Services\OrderService\GetParamByOrderHeaderTest;
  3. use App\Commodity;
  4. use App\Logistic;
  5. use App\OracleBasCode;
  6. use App\OracleDOCOrderHeader;
  7. use App\Order;
  8. use App\Owner;
  9. use App\Services\LogisticService;
  10. use App\Services\OracleDOCOrderHeaderService;
  11. use App\Services\OrderIssueService;
  12. use App\Services\OrderService;
  13. use App\Services\OwnerService;
  14. use App\Services\ShopService;
  15. use App\Services\WarehouseService;
  16. use App\Shop;
  17. use App\Warehouse;
  18. use Illuminate\Foundation\Testing\RefreshDatabase;
  19. use Illuminate\Foundation\Testing\WithFaker;
  20. use Illuminate\Support\Facades\DB;
  21. use Tests\TestCase;
  22. class GetParamByOrderHeaderTest extends TestCase
  23. {
  24. /** @var OrderService $service */
  25. private $service;
  26. private $data = [];
  27. public function setUp(): void
  28. {
  29. parent::setUp();
  30. $this->service = app(OrderService::class);
  31. // $this->data['owner'] = factory(Owner::class)->create(['name'=>'测试货主']);
  32. $wmsOrderHeader = factory(OracleDOCOrderHeader::class)->make([
  33. 'customerid'=>'TEST_OW','sostatus'=>99,'userdefine1'=>'TEST_CA','warehouseid'=>'WH_TEST'
  34. ]);
  35. $orderType = factory(OracleBasCode::class)->make(['code'=>'sysy', 'codeid'=>'SO_TYP', 'codename_c'=>'测试状态']);
  36. $wmsOrderHeader->setRelation('orderType',$orderType);
  37. $code_BasCode = factory(OracleBasCode::class)->make(['codeid'=>'OW','code'=>'99','descr_c'=>'订单完成']);
  38. $wmsOrderHeader->setRelation('oracleBASCode',$code_BasCode);
  39. $this->data['orderHeader'] = $wmsOrderHeader;
  40. DB::insert('insert ignore into warehouses (code) values(?)',['WH_TEST']);
  41. $this->data['warehouse'] = Warehouse::query()->where('code','WH_TEST')->first();
  42. DB::insert('insert ignore into logistics (code,name) values(?,?)',['TEST_CA','测试承运商']);
  43. $this->data['logistic'] = Logistic::query()->where('code','TEST_CA')->where('name','测试承运商')->first();
  44. $this->data['owner'] = factory(Owner::class)->create(['code'=>'TEST_OW','name'=>'测试货主']);
  45. $this->data['shop'] = factory(Shop::class)->create(['owner_id'=>$this->data['owner']['id']]);
  46. $this->mock(OracleDOCOrderHeaderService::class,function($mock)use($wmsOrderHeader){
  47. $mock->shouldReceive('first')->andReturn($wmsOrderHeader);
  48. });
  49. }
  50. /**
  51. * @test
  52. */
  53. public function testGetParamByOrderHeader()
  54. {
  55. $orderHeader = $this->data['orderHeader'] ;
  56. $orderHeaders = collect([$orderHeader]);
  57. app(ShopService::class)->getByWmsOrders($orderHeaders);
  58. app(OwnerService::class)->getByWmsOrders($orderHeaders);
  59. app(LogisticService::class)->getByWmsOrders($orderHeaders);
  60. app(WarehouseService::class)->getByWmsOrders($orderHeaders);
  61. $param = $this->service->getParamByOrderHeader($orderHeader);
  62. $this->assertNotNull($param);
  63. $this->assertNotEmpty($param['code']);
  64. $this->assertNotEmpty($param['owner_id']);
  65. $this->assertNotNull($param['logistic_id']);
  66. // $this->assertNotEmpty($param['consignee_name']);
  67. // $this->assertNotEmpty($param['consignee_phone']);
  68. // $this->assertNotEmpty($param['province']);
  69. // $this->assertNotEmpty($param['city']);
  70. // $this->assertNotEmpty($param['district']);
  71. // $this->assertNotEmpty($param['address']);
  72. // $this->assertNotEmpty($param['client_code']);
  73. $this->assertNotEmpty($param['wms_edittime']);
  74. $this->assertNotEmpty($param['wms_status']);
  75. $this->assertNotEmpty($param['updated_at']);
  76. $this->assertNotEmpty($param['created_at']);
  77. $this->assertNotEmpty($param['warehouse_id']);
  78. }
  79. public function tearDown(): void
  80. {
  81. cache()->forget("getLogisticByCode_{$this->data['logistic']['code']}");
  82. cache()->forget("getOwnerByCode_{$this->data['owner']['code']}");
  83. cache()->forget("getShopByCodeMap_{$this->data['shop']['code']}");
  84. cache()->forget("WareHouse_{$this->data['warehouse']['code']}");
  85. // $order = Order::query()->where('code',$this->data['orderHeader']['orderno'])->first();
  86. // $order->delete();
  87. Shop::query()->where('owner_id',$this->data['owner']['id'])->delete();
  88. Logistic::query()->where('code','TEST_CA')->where('name','测试承运商')->forceDelete();
  89. Owner::query()->where('name','测试货主')->delete();
  90. Warehouse::query()->where('code','WH_TEST')->delete();
  91. parent::tearDown(); // TODO: Change the autogenerated stub
  92. }
  93. }