GetParamByOrderHeaderTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. DB::insert('insert ignore into owners (code,name) values(?,?)',['TEST_OW','测试货主']);
  46. $this->data['owner'] = Owner::query()->where('code','TEST_OW')->where('name','测试货主')->first();
  47. $this->data['shop'] = factory(Shop::class)->create(['owner_id'=>$this->data['owner']['id']]);
  48. $this->mock(OracleDOCOrderHeaderService::class,function($mock)use($wmsOrderHeader){
  49. $mock->shouldReceive('first')->andReturn($wmsOrderHeader);
  50. });
  51. }
  52. /**
  53. * @test
  54. */
  55. public function testGetParamByOrderHeader()
  56. {
  57. $orderHeader = $this->data['orderHeader'] ;
  58. $orderHeaders = collect([$orderHeader]);
  59. app(ShopService::class)->getByWmsOrders($orderHeaders);
  60. app(OwnerService::class)->getByWmsOrders($orderHeaders);
  61. app(LogisticService::class)->getByWmsOrders($orderHeaders);
  62. app(WarehouseService::class)->getByWmsOrders($orderHeaders);
  63. $param = $this->service->getParamByOrderHeader($orderHeader);
  64. $this->assertNotNull($param);
  65. $this->assertNotEmpty($param['code']);
  66. $this->assertNotEmpty($param['owner_id']);
  67. $this->assertNotNull($param['logistic_id']);
  68. // $this->assertNotEmpty($param['consignee_name']);
  69. // $this->assertNotEmpty($param['consignee_phone']);
  70. // $this->assertNotEmpty($param['province']);
  71. // $this->assertNotEmpty($param['city']);
  72. // $this->assertNotEmpty($param['district']);
  73. // $this->assertNotEmpty($param['address']);
  74. // $this->assertNotEmpty($param['client_code']);
  75. $this->assertNotEmpty($param['wms_edittime']);
  76. $this->assertNotEmpty($param['wms_status']);
  77. $this->assertNotEmpty($param['updated_at']);
  78. $this->assertNotEmpty($param['created_at']);
  79. $this->assertNotEmpty($param['warehouse_id']);
  80. }
  81. public function tearDown(): void
  82. {
  83. cache()->forget("getLogisticByCode_{$this->data['logistic']['code']}");
  84. cache()->forget("getOwnerByCode_{$this->data['owner']['code']}");
  85. cache()->forget("getShopByCodeMap_{$this->data['shop']['code']}");
  86. cache()->forget("WareHouse_{$this->data['warehouse']['code']}");
  87. // $order = Order::query()->where('code',$this->data['orderHeader']['orderno'])->first();
  88. // $order->delete();
  89. Shop::query()->where('owner_id',$this->data['owner']['id'])->delete();
  90. Logistic::query()->where('code','TEST_CA')->where('name','测试承运商')->forceDelete();
  91. Owner::query()->where('name','测试货主')->delete();
  92. Warehouse::query()->where('code','WH_TEST')->delete();
  93. parent::tearDown(); // TODO: Change the autogenerated stub
  94. }
  95. }