CreateByBatchesTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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['stationType'] =
  37. // factory(StationType::class)
  38. // ->create();
  39. $this->data['stationRuleBatch'] =
  40. factory(StationRuleBatch::class)
  41. -> create([
  42. 'owner_id'=>$this->data['owner']['id'],
  43. ]);
  44. $this->data['stationTasks'] =
  45. $this->stationTaskService->create(self::AmountOfBatch);
  46. }
  47. public function testReturned()
  48. {
  49. $this->data['stationTaskBatches']=$this->service->createByBatches($this->data['batches'], $this->data['stationTasks']);
  50. $this->assertEquals(self::AmountOfBatch, $this->data['stationTaskBatches']->count());
  51. }
  52. public function tearDown(): void
  53. {
  54. Batch::query()->whereIn('id',data_get($this->data['batches'],'*.id')??[])->delete();
  55. StationTask::query()->whereIn('id',data_get($this->data['stationTasks'],'*.id')??[])->delete();
  56. StationTaskBatch::query()->whereIn('id',data_get($this->data['stationTaskBatches'],'*.id')??[])->delete();
  57. StationTaskChild::query()->whereIn('station_task_id',data_get($this->data['stationTaskBatches'],'*.id')??[])->delete();
  58. Owner::query()->where('id',$this->data['owner']['id']??'')->delete();
  59. parent::tearDown();
  60. }
  61. }