RunManyTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace Tests\Services\StationTaskBatchService;
  3. use App\Batch;
  4. use App\MaterialBox;
  5. use App\Order;
  6. use App\OrderCommodity;
  7. use App\Owner;
  8. use App\Services\ForeignHaiRoboticsService;
  9. use App\Services\MaterialBoxService;
  10. use App\Services\StationTaskBatchService;
  11. use App\Services\StationTaskCommodityService;
  12. use App\Services\StationTaskMaterialBoxService;
  13. use App\Services\StationTaskService;
  14. use App\StationRuleBatch;
  15. use App\StationTask;
  16. use App\StationTaskCommodity;
  17. use App\StationTaskMaterialBox;
  18. use Tests\TestCase;
  19. use App\StationTaskBatch;
  20. use App\Traits\TestMockSubServices;
  21. class RunManyTest extends TestCase
  22. {
  23. use TestMockSubServices;
  24. /** @var StationTaskBatchService $stationTaskBatchService */
  25. public $stationTaskBatchService;
  26. /** @var StationTaskService $stationTaskService */
  27. public $stationTaskService;
  28. /** @var StationTaskCommodityService $stationTaskCommodityService */
  29. public $stationTaskCommodityService;
  30. /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
  31. public $stationTaskMaterialBoxService;
  32. private $data;
  33. private $bathAmount=3;
  34. function setUp(): void
  35. {
  36. parent::setUp();
  37. $this->stationTaskService = app('StationTaskService');
  38. $this->stationTaskCommodityService = app('StationTaskCommodityService');
  39. $this->stationTaskMaterialBoxService = app('StationTaskMaterialBoxService');
  40. $this->stationTaskBatchService=$this->subMock([
  41. 'class'=>StationTaskBatchService::class,
  42. // 'subServices'=>[
  43. // [
  44. // 'serviceName'=>'foreignHaiRoboticsService',
  45. // 'class'=>ForeignHaiRoboticsService::class,
  46. // 'methods'=>[
  47. // 'fetchGroup'=>true,
  48. // ],
  49. // ],
  50. // ]
  51. ]);
  52. $this->data['owner'] =
  53. factory(Owner::class)
  54. ->create();
  55. $this->data['batches'] =
  56. factory(Batch::class,
  57. $this->bathAmount)
  58. ->create([
  59. 'status'=>'未处理',
  60. 'owner_id'=>$this->data['owner']['id']
  61. ]);
  62. $this->data['stationRuleBatch'] =
  63. factory(StationRuleBatch::class)
  64. -> create([
  65. 'owner_id'=>$this->data['owner']['id'],
  66. ]);
  67. $this->data['stationTask'] =
  68. $this->stationTaskService->create($this->bathAmount);
  69. $this->data['stationTaskCommodities']=$this->stationTaskCommodityService->createByBatches($this->data['batches'],$this->data['stationTask']); //注册商品任务
  70. $this->data['stationTaskMaterialBoxes']=$this->stationTaskMaterialBoxService->createByBatches($this->data['batches'],$this->data['stationTask']); //注册料箱任务
  71. $this->data['stationTaskBathes']=$this->stationTaskBatchService->createByBatches($this->data['batches'],$this->data['stationTask']); //注册波次任务
  72. }
  73. public function testReturned()
  74. {
  75. $taskBatches_failed=$this->stationTaskBatchService->runMany(
  76. $this->data['stationTaskBathes']
  77. );
  78. $this->assertTrue($taskBatches_failed->isEmpty());
  79. $this->assertTrue((
  80. $全部是处理中状态
  81. =function(){
  82. $arr=array_unique(
  83. data_get($this->data['stationTaskBathes'],'*.status')
  84. );
  85. return
  86. count($arr)==1
  87. && $arr[0]=='处理中';
  88. })());
  89. }
  90. function tearDown(): void
  91. {
  92. StationTaskBatch::query()
  93. ->whereIn('id',data_get($this->data['stationTaskBathes'],'*.id')??[])
  94. ->delete();
  95. StationRuleBatch::query()
  96. ->whereIn('id',$this->data['stationRuleBatch']['id'])
  97. ->delete();
  98. StationTaskMaterialBox::query()
  99. ->whereIn('id',data_get($this->data['batches'],'*.id')??[])
  100. ->delete();
  101. Order::query()
  102. ->whereIn('id',data_get($this->data['orders'],'*.id')??[])
  103. ->delete();
  104. MaterialBox::query()
  105. ->whereIn('id',data_get($this->data['materialBoxes'],'*.id')??[])
  106. ->delete();
  107. OrderCommodity::query()
  108. ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
  109. ->delete();
  110. StationTask::query()
  111. ->whereIn('id',data_get($this->data['stationTask'],'*.id')??[])
  112. ->delete();
  113. StationTaskCommodity::query()
  114. ->whereIn('id',data_get($this->data['stationTaskCommodities'],'*.id')??[])
  115. ->delete();
  116. parent::tearDown();
  117. }
  118. }