CreateByBatchesTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Tests\Services\StationTaskBatchService;
  3. use App\Batch;
  4. use App\Services\StationTaskBatchService;
  5. use App\Services\StationTaskService;
  6. use App\StationTask;
  7. use App\StationTaskBatch;
  8. use Tests\TestCase;
  9. class CreateByBatchesTest extends TestCase
  10. {
  11. /** @var StationTaskBatchService $service */
  12. private $service;
  13. /** @var StationTaskService $service */
  14. private $stationTaskService;
  15. private $data = [];
  16. const AmountOfBatch=3;
  17. public function setUp(): void
  18. {
  19. parent::setUp();
  20. $this->service = app('StationTaskBatchService');
  21. $this->stationTaskService = app('StationTaskService');
  22. $this->data['batches'] =
  23. factory(Batch::class, self::AmountOfBatch)
  24. ->create();
  25. $this->data['stationTasks'] =
  26. $this->stationTaskService->create(self::AmountOfBatch);
  27. }
  28. public function testReturned()
  29. {
  30. $this->data['stationTaskBatches']=$this->service->createByBatches($this->data['batches'], $this->data['stationTasks']);
  31. $this->assertEquals(self::AmountOfBatch, $this->data['stationTaskBatches']->count());
  32. }
  33. public function tearDown(): void
  34. {
  35. Batch::query()->whereIn('id',data_get($this->data['batches'],'*.id')??[])->delete();
  36. StationTask::query()->whereIn('id',data_get($this->data['stationTasks'],'*.id')??[])->delete();
  37. StationTaskBatch::query()->whereIn('id',data_get($this->data['stationTaskBatches'],'*.id')??[])->delete();
  38. parent::tearDown();
  39. }
  40. }