CreateByBatchesTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\StationType;
  11. use Tests\TestCase;
  12. class CreateByBatchesTest extends TestCase
  13. {
  14. /** @var StationTaskBatchService $service */
  15. private $service;
  16. /** @var StationTaskService $service */
  17. private $stationTaskService;
  18. private $data = [];
  19. const AmountOfBatch=3;
  20. public function setUp(): void
  21. {
  22. parent::setUp();
  23. $this->service = app('StationTaskBatchService');
  24. $this->stationTaskService = app('StationTaskService');
  25. $this->data['owner'] =
  26. factory(Owner::class)
  27. ->create();
  28. $this->data['batches'] =
  29. factory(Batch::class,
  30. self::AmountOfBatch)
  31. ->create([
  32. 'status'=>'未处理',
  33. 'owner_id'=>$this->data['owner']['id']
  34. ]);
  35. $this->data['stationType'] =
  36. factory(StationType::class)
  37. -> create();
  38. $this->data['stationRuleBatch'] =
  39. factory(StationRuleBatch::class)
  40. -> create([
  41. 'owner_id'=>$this->data['owner']['id']
  42. ]);
  43. $this->data['stationTasks'] =
  44. $this->stationTaskService->create(self::AmountOfBatch);
  45. }
  46. public function testReturned()
  47. {
  48. $this->data['stationTaskBatches']=$this->service->createByBatches($this->data['batches'], $this->data['stationTasks']);
  49. $this->assertEquals(self::AmountOfBatch, $this->data['stationTaskBatches']->count());
  50. }
  51. public function tearDown(): void
  52. {
  53. Batch::query()->whereIn('id',data_get($this->data['batches'],'*.id')??[])->delete();
  54. StationTask::query()->whereIn('id',data_get($this->data['stationTasks'],'*.id')??[])->delete();
  55. StationTaskBatch::query()->whereIn('id',data_get($this->data['stationTaskBatches'],'*.id')??[])->delete();
  56. Owner::query()->where('id',$this->data['owner']['id']??'')->delete();
  57. parent::tearDown();
  58. }
  59. }