AssignTasksTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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->data['batches']->load('stationTaskBatch');
  78. $this->assertEquals(
  79. data_get($this->data['batches'],'*.id'),
  80. data_get($this->data['batches'],'*.stationTaskBatch.batch_id')
  81. );
  82. })();
  83. }
  84. function tearDown(): void
  85. {
  86. // $stationTaskBatchs=data_get($this->data['batches'],'*.stationTaskBatch');
  87. // foreach ($stationTaskBatchs as $stationTaskBatch){
  88. // $stationTaskBatch->loadMissing('stationTask.stationTaskCommodities');
  89. // $stationTaskBatch->loadMissing('stationTask.stationTaskMaterialBoxes.materialBox');
  90. // }
  91. // MaterialBox::query()
  92. // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskMaterialBoxes.*.materialBox.id')??[])
  93. // ->delete();
  94. // StationTaskMaterialBox::query()
  95. // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskMaterialBoxes.*.id')??[])
  96. // ->delete();
  97. // StationTaskCommodity::query()
  98. // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskCommodities.*.id')??[])
  99. // ->delete();
  100. // StationTaskBatch::query()
  101. // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.id')??[])
  102. // ->delete();
  103. // StationTask::query()
  104. // ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.id')??[])
  105. // ->delete();
  106. // StationRuleBatch::query()
  107. // ->whereIn('id',data_get($this->data['station_rule_batches'],'*.id')??[])
  108. // ->delete();
  109. // OrderCommodity::query()
  110. // ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
  111. // ->delete();
  112. // Order::query()
  113. // ->whereIn('id',data_get($this->data['orders'],'*.id')??[])
  114. // ->delete();
  115. // Batch::query()
  116. // ->whereIn('id',data_get($this->data['batches'],'*.id')??[])
  117. // ->delete();
  118. parent::tearDown();
  119. }
  120. }