AssignTasksTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace Tests\Services\BatchService;
  3. use App\MaterialBox;
  4. use App\Order;
  5. use App\OrderCommodity;
  6. use App\Services\BatchService;
  7. use App\Services\ForeignHaiRoboticsService;
  8. use App\Services\MaterialBoxService;
  9. use App\Services\StationTaskBatchService;
  10. use App\Services\StationTaskCommodityService;
  11. use App\Station;
  12. use App\StationRuleBatch;
  13. use App\StationTask;
  14. use App\StationTaskBatch;
  15. use App\StationTaskCommodity;
  16. use App\StationTaskMaterialBox;
  17. use Tests\TestCase;
  18. use App\Batch;
  19. use App\Traits\TestMockSubServices;
  20. class AssignTasksTest extends TestCase
  21. {
  22. use TestMockSubServices;
  23. /** @var BatchService $service */
  24. public $service;
  25. private $data;
  26. private $batchAmount=2;
  27. private $orderAmount=4;
  28. private $orderCommodityAmount=8;
  29. function setUp(): void
  30. {
  31. parent::setUp();
  32. $this->service=$this->subMock([
  33. 'class'=>BatchService::class,
  34. 'subServices'=>[
  35. [
  36. 'serviceName'=>'stationTaskBatchService',
  37. 'class'=>StationTaskBatchService::class,
  38. 'methods'=>[
  39. 'firstOrCreate'=>new MaterialBox(['id'=>1]),
  40. ],
  41. 'subServices'=>[
  42. [
  43. 'serviceName'=>'foreignHaiRoboticsService',
  44. 'class'=>ForeignHaiRoboticsService::class,
  45. 'methods'=>[
  46. 'fetchGroup'=>true,
  47. ],
  48. ],
  49. ]
  50. ],
  51. ]
  52. ]);
  53. $this->data['batches']
  54. = factory(Batch::class, $this->batchAmount)
  55. ->create();
  56. $this->data['orders'] =
  57. factory(Order::class)
  58. ->createMany($this->makeArray($this->orderAmount,[
  59. 'status'=>'未处理',
  60. 'batch_id' => function(){return $this->getTargetIdCirculately($this->data['batches']);}
  61. ]));
  62. $this->data['orderCommodities'] =
  63. factory(OrderCommodity::class)
  64. ->createMany($this->makeArray($this->orderCommodityAmount,[
  65. 'order_id' => function(){return $this->getTargetIdCirculately($this->data['orders']);}
  66. ]));
  67. $this->data['station_rule_batches']
  68. = factory(StationRuleBatch::class)
  69. ->createMany($this->makeArray($this->batchAmount,[
  70. 'owner_id' => function(){return $this->getTargetIdCirculately($this->data['batches'],'','owner_id');}
  71. ]));
  72. }
  73. public function testReturned()
  74. {
  75. $this->service->assignTasks($this->data['batches']);
  76. ($波次任务指向了波次=function(){
  77. $this->assertEquals(
  78. data_get($this->data['batches'],'*.id'),
  79. data_get($this->data['batches'],'*.stationTaskBatch.batch_id')
  80. );
  81. })();
  82. }
  83. function tearDown(): void
  84. {
  85. $stationTaskBatchs=data_get($this->data['batches'],'*.stationTaskBatch');
  86. foreach ($stationTaskBatchs as $stationTaskBatch){
  87. $stationTaskBatch->loadMissing('stationTask.stationTaskCommodities');
  88. $stationTaskBatch->loadMissing('stationTask.stationTaskMaterialBoxes.materialBox');
  89. }
  90. // MaterialBox::query()
  91. // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskMaterialBoxes.*.materialBox.id')??[])
  92. // ->delete();
  93. // StationTaskMaterialBox::query()
  94. // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskMaterialBoxes.*.id')??[])
  95. // ->delete();
  96. StationTaskCommodity::query()
  97. ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskCommodities.*.id')??[])
  98. ->delete();
  99. StationTaskBatch::query()
  100. ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.id')??[])
  101. ->delete();
  102. // StationTask::query()
  103. // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.id')??[])
  104. // ->delete();
  105. StationRuleBatch::query()
  106. ->whereIn('id',data_get($this->data['station_rule_batches'],'*.id')??[])
  107. ->delete();
  108. OrderCommodity::query()
  109. ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
  110. ->delete();
  111. Order::query()
  112. ->whereIn('id',data_get($this->data['orders'],'*.id')??[])
  113. ->delete();
  114. Batch::query()
  115. ->whereIn('id',data_get($this->data['batches'],'*.id')??[])
  116. ->delete();
  117. parent::tearDown();
  118. }
  119. }