AssignTasksTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace Tests\Services\BatchService;
  3. use App\MaterialBox;
  4. use App\Order;
  5. use App\OrderCommodity;
  6. use App\Owner;
  7. use App\Services\BatchService;
  8. use App\Services\ForeignHaiRoboticsService;
  9. use App\Services\StationTaskBatchService;
  10. use App\StationRuleBatch;
  11. use App\StationTask;
  12. use App\StationTaskBatch;
  13. use App\StationTaskCommodity;
  14. use App\StationTaskMaterialBox;
  15. use Ramsey\Uuid\Uuid;
  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=3;
  26. private $orderAmount=5;
  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['owner']
  53. = factory(Owner::class)
  54. ->create();
  55. $this->data['batches']
  56. = factory(Batch::class, $this->batchAmount)
  57. ->create(['owner_id'=>$this->data['owner']['id']]);
  58. $this->data['orders'] =
  59. factory(Order::class)
  60. ->createMany($this->makeArray($this->orderAmount,[
  61. 'status'=>'未处理',
  62. 'batch_id' => function(){return $this->getTargetFieldCirculately($this->data['batches']);}
  63. ]));
  64. $this->data['orderCommodities'] =
  65. factory(OrderCommodity::class)
  66. ->createMany($this->makeArray($this->orderCommodityAmount,[
  67. 'order_id' => function(){return $this->getTargetFieldCirculately($this->data['orders']);},
  68. 'location' => function(){return 'IDE' . rand(1, 6);},
  69. ]));
  70. $this->data['station_rule_batches']
  71. = factory(StationRuleBatch::class)
  72. ->createMany($this->makeArray($this->batchAmount,[
  73. 'owner_id' => function(){return $this->getTargetFieldCirculately($this->data['batches'],'','owner_id');}
  74. ]));
  75. }
  76. public function testReturned()
  77. {
  78. $this->service->assignTasks($this->data['batches']);
  79. ($波次任务指向了波次=function(){
  80. $this->data['batches']->load('stationTaskBatch');
  81. $this->assertEquals(
  82. data_get($this->data['batches'],'*.id'),
  83. data_get($this->data['batches'],'*.stationTaskBatch.batch_id')
  84. );
  85. })();
  86. }
  87. function tearDown(): void
  88. {
  89. MaterialBox::query()
  90. ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskMaterialBoxes.*.materialBox.id')??[])
  91. ->delete();
  92. StationTaskMaterialBox::query()
  93. ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskMaterialBoxes.*.id')??[])
  94. ->delete();
  95. StationTaskCommodity::query()
  96. ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskCommodities.*.id')??[])
  97. ->delete();
  98. StationTaskBatch::query()
  99. ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.id')??[])
  100. ->delete();
  101. StationTask::query()
  102. ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.id')??[])
  103. ->delete();
  104. StationRuleBatch::query()
  105. ->whereIn('id',data_get($this->data['station_rule_batches'],'*.id')??[])
  106. ->delete();
  107. OrderCommodity::query()
  108. ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
  109. ->delete();
  110. Order::query()
  111. ->whereIn('id',data_get($this->data['orders'],'*.id')??[])
  112. ->delete();
  113. Batch::query()
  114. ->whereIn('id',data_get($this->data['batches'],'*.id')??[])
  115. ->delete();
  116. Owner::query()
  117. ->where('id',$this->data['owner']['id']??'')
  118. ->delete();
  119. parent::tearDown();
  120. }
  121. }