RunManyTest.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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=2;
  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['orders'] =
  63. factory(Order::class)
  64. ->createMany($this->makeArray($this->bathAmount, [
  65. 'batch_id' => function () {
  66. return $this->getTargetFieldCirculately($this->data['batches']);
  67. }
  68. ]));
  69. $this->data['orderCommodities'] =
  70. factory(OrderCommodity::class)
  71. ->createMany($this->makeArray($this->bathAmount, [
  72. 'order_id' => function () {
  73. return $this->getTargetFieldCirculately($this->data['orders']);
  74. }
  75. ]));
  76. $this->data['material_boxes']
  77. = factory(MaterialBox::class)
  78. ->createMany($this->makeArray($this->bathAmount, [
  79. 'code' => function () {
  80. return $this->getTargetFieldCirculately($this->data['orderCommodities'], MaterialBox::class, 'location');
  81. }
  82. ]));
  83. $this->data['stationRuleBatch'] =
  84. factory(StationRuleBatch::class)
  85. -> create([
  86. 'owner_id'=>$this->data['owner']['id'],
  87. ]);
  88. $this->data['stationTask'] =
  89. $this->stationTaskService->create($this->bathAmount);
  90. $this->data['stationTaskCommodities']=$this->stationTaskCommodityService->createByBatches($this->data['batches'],$this->data['stationTask']); //注册商品任务
  91. $this->data['stationTaskMaterialBoxes']=$this->stationTaskMaterialBoxService->createByBatches($this->data['batches'],$this->data['stationTask']); //注册料箱任务
  92. $this->data['stationTaskBathes']=$this->stationTaskBatchService->createByBatches($this->data['batches'],$this->data['stationTask']); //注册波次任务
  93. }
  94. public function testReturned()
  95. {
  96. $taskBatches_failed=$this->stationTaskBatchService->runMany(
  97. $this->data['stationTaskBathes']
  98. );
  99. $this->assertTrue($taskBatches_failed->isEmpty());
  100. $this->assertTrue(($全部是处理中状态 =function(){
  101. $arr=array_unique(
  102. data_get($this->data['stationTaskBathes'],'*.status')
  103. );
  104. return
  105. count($arr)==1
  106. && $arr[0]=='待处理';
  107. })());
  108. }
  109. function tearDown(): void
  110. {
  111. StationTaskBatch::query()
  112. ->whereIn('id',data_get($this->data['stationTaskBathes'],'*.id')??[])
  113. ->delete();
  114. StationTaskMaterialBox::query()
  115. ->whereIn('id',data_get($this->data['stationTaskMaterialBoxes'],'*.id')??[])
  116. ->delete();
  117. Order::query()
  118. ->whereIn('id',data_get($this->data['orders'],'*.id')??[])
  119. ->delete();
  120. MaterialBox::query()
  121. ->whereIn('id',data_get($this->data['material_boxes'],'*.id')??[])
  122. ->delete();
  123. OrderCommodity::query()
  124. ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
  125. ->delete();
  126. StationTaskCommodity::query()
  127. ->whereIn('id',data_get($this->data['stationTaskCommodities'],'*.id')??[])
  128. ->delete();
  129. StationTask::query()
  130. ->whereIn('id',data_get($this->data['stationTask'],'*.id')??[])
  131. ->delete();
  132. StationRuleBatch::query()->where('id',$this->data['stationRuleBatch']['id'])->delete();
  133. Batch::query()->whereIn('id',data_get($this->data['batches'],'*.id'))->delete();
  134. Owner::query()->where('id',$this->data['owner']['id'])->delete();
  135. parent::tearDown();
  136. }
  137. }