AssignTasksTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. try {
  79. $this->service->assignTasks($this->data['batches']);
  80. } catch (\Exception $e) {
  81. }
  82. ($波次任务指向了波次=function(){
  83. $this->data['batches']->load('stationTaskBatch');
  84. // dump(data_get($this->data['batches'],'*.id'),data_get($this->data['batches'],'*.stationTaskBatch.batch_id'));
  85. // dd(array_diff(data_get($this->data['batches'],'*.id'),data_get($this->data['batches'],'*.stationTaskBatch.batch_id')));
  86. $this->assertEquals(
  87. data_get($this->data['batches'],'*.id'),
  88. data_get($this->data['batches'],'*.stationTaskBatch.batch_id')
  89. );
  90. })();
  91. }
  92. function tearDown(): void
  93. {
  94. MaterialBox::query()
  95. ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskMaterialBoxes.*.materialBox.id')??[])
  96. ->delete();
  97. StationTaskMaterialBox::query()
  98. ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskMaterialBoxes.*.id')??[])
  99. ->delete();
  100. StationTaskCommodity::query()
  101. ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.stationTaskCommodities.*.id')??[])
  102. ->delete();
  103. StationTaskBatch::query()
  104. ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.id')??[])
  105. ->delete();
  106. StationTask::query()
  107. ->whereIn('id',data_get($this->data['batches'],'*.stationTaskBatch.stationTask.id')??[])
  108. ->delete();
  109. StationRuleBatch::query()
  110. ->whereIn('id',data_get($this->data['station_rule_batches'],'*.id')??[])
  111. ->delete();
  112. OrderCommodity::query()
  113. ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
  114. ->delete();
  115. Order::query()
  116. ->whereIn('id',data_get($this->data['orders'],'*.id')??[])
  117. ->delete();
  118. Batch::query()
  119. ->whereIn('id',data_get($this->data['batches'],'*.id')??[])
  120. ->delete();
  121. Owner::query()
  122. ->where('id',$this->data['owner']['id']??'')
  123. ->delete();
  124. parent::tearDown();
  125. }
  126. }