CreateByBatchesTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Tests\Services\StationTaskBatchService;
  3. use App\Batch;
  4. use App\Owner;
  5. use App\Services\StationTaskBatchService;
  6. use App\Services\StationTaskService;
  7. use App\StationRuleBatch;
  8. use App\StationTask;
  9. use App\StationTaskBatch;
  10. use App\StationTaskChild;
  11. use App\StationType;
  12. use Tests\TestCase;
  13. class CreateByBatchesTest extends TestCase
  14. {
  15. /** @var StationTaskBatchService $service */
  16. private $service;
  17. /** @var StationTaskService $service */
  18. private $stationTaskService;
  19. private $data = [];
  20. const AmountOfBatch=3;
  21. public function setUp(): void
  22. {
  23. parent::setUp();
  24. $this->service = app('StationTaskBatchService');
  25. $this->stationTaskService = app('StationTaskService');
  26. $this->data['owner'] =
  27. factory(Owner::class)
  28. ->create();
  29. $this->data['batches'] =
  30. factory(Batch::class,
  31. self::AmountOfBatch)
  32. ->create([
  33. 'status'=>'未处理',
  34. 'owner_id'=>$this->data['owner']['id']
  35. ]);
  36. $this->data['stationRuleBatch'] =
  37. factory(StationRuleBatch::class)
  38. -> create([
  39. 'owner_id'=>$this->data['owner']['id'],
  40. ]);
  41. $this->data['stationTasks'] =
  42. $this->stationTaskService->create(self::AmountOfBatch);
  43. }
  44. public function testReturned()
  45. {
  46. $this->data['stationTaskBatches']
  47. =$this->service->createByBatches($this->data['batches'], $this->data['stationTasks']);
  48. $this->assertEquals(self::AmountOfBatch, $this->data['stationTaskBatches']->count());
  49. $this->assertEquals(
  50. data_get($this->data['stationTasks'],'*.id'),
  51. $this->data['stationTaskBatches']->map(function($taskBatch){
  52. $taskBatch->loadMissing('stationTask');
  53. return $taskBatch['stationTask']['station_task_id'];
  54. })->toArray()
  55. );
  56. }
  57. public function tearDown(): void
  58. {
  59. // Batch::query()->whereIn('id',data_get($this->data['batches'],'*.id')??[])->delete();
  60. // StationTask::query()->whereIn('id',data_get($this->data['stationTasks'],'*.id')??[])->delete();
  61. // StationTaskBatch::query()->whereIn('id',data_get($this->data['stationTaskBatches'],'*.id')??[])->delete();
  62. // StationTaskChild::query()->whereIn('station_task_id',data_get($this->data['stationTasks'],'*.id')??[])->delete();
  63. // Owner::query()->where('id',$this->data['owner']['id']??'')->delete();
  64. parent::tearDown();
  65. }
  66. }