RunManyTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Tests\Services\StationTaskBatchService;
  3. use App\Batch;
  4. use App\MaterialBox;
  5. use App\Order;
  6. use App\OrderCommodity;
  7. use App\Owner;
  8. use App\Services\StationTaskBatchService;
  9. use App\StationRuleBatch;
  10. use App\StationTask;
  11. use App\StationTaskMaterialBox;
  12. use Tests\TestCase;
  13. use App\StationTaskBatch;
  14. use App\Traits\TestMockSubServices;
  15. class RunManyTest extends TestCase
  16. {
  17. use TestMockSubServices;
  18. /** @var StationTaskBatchService $service */
  19. public $service;
  20. private $data;
  21. private $bathAmount=3;
  22. function setUp(): void
  23. {
  24. parent::setUp();
  25. $this->service = app('StationTaskBatchService');
  26. $this->stationTaskService = app('StationTaskService');
  27. $this->data['stationTaskBathes']
  28. = factory(StationTaskBatch::class, $this->bathAmount)
  29. ->create();
  30. $this->data['owner'] =
  31. factory(Owner::class)
  32. ->create();
  33. $this->data['batches'] =
  34. factory(Batch::class,
  35. $this->bathAmount)
  36. ->create([
  37. 'status'=>'未处理',
  38. 'owner_id'=>$this->data['owner']['id']
  39. ]);
  40. $this->data['stationRuleBatch'] =
  41. factory(StationRuleBatch::class)
  42. -> create([
  43. 'owner_id'=>$this->data['owner']['id'],
  44. ]);
  45. $this->data['stationTasks'] =
  46. $this->stationTaskService->create($this->bathAmount);
  47. }
  48. public function testReturned()
  49. {
  50. $taskBatches_failed=$this->service->runMany(
  51. $this->data['stationTaskBathes']
  52. );
  53. $this->assertTrue($taskBatches_failed->isEmpty());
  54. $this->assertTrue((function(){
  55. $arr=array_unique(
  56. data_get($this->data['stationTaskBathes'],'*.status')
  57. );
  58. })());
  59. }
  60. function tearDown(): void
  61. {
  62. StationTaskBatch::query()
  63. ->whereIn('id',data_get($this->data['stationTaskBathes'],'*.id')??[])
  64. ->delete();
  65. StationTaskMaterialBox::query()
  66. ->whereIn('id',data_get($this->data['batches'],'*.id')??[])
  67. ->delete();
  68. Order::query()
  69. ->whereIn('id',data_get($this->data['orders'],'*.id')??[])
  70. ->delete();
  71. MaterialBox::query()
  72. ->whereIn('id',data_get($this->data['materialBoxes'],'*.id')??[])
  73. ->delete();
  74. OrderCommodity::query()
  75. ->whereIn('id',data_get($this->data['orderCommodities'],'*.id')??[])
  76. ->delete();
  77. StationTask::query()
  78. ->whereIn('id',data_get($this->data['stationTasks'],'*.id')??[])
  79. ->delete();
  80. parent::tearDown();
  81. }
  82. }