AssignTasksTest.php 4.6 KB

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