CreateTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Tests\Services\StationTaskService;
  3. use App\Batch;
  4. use App\Owner;
  5. use App\Services\BatchService;
  6. use App\Services\StationRuleBatchService;
  7. use App\StationRuleBatch;
  8. use Tests\TestCase;
  9. class CreateTest extends TestCase
  10. {
  11. /** @var StationRuleBatchService $service */
  12. private $service;
  13. /** @var BatchService $batchService */
  14. private $batchService;
  15. private $data = [];
  16. private $amountOfInRule = 3;
  17. public function setUp(): void
  18. {
  19. parent::setUp();
  20. $this->service = app('StationRuleBatchService');
  21. $this->batchService = app('BatchService');
  22. $this->data['owner_target'] = factory(Owner::class)->create();
  23. $this->data['owner_none_target'] = factory(Owner::class)->create();
  24. $this->data['stationRuleBatch'] = factory(StationRuleBatch::class)
  25. ->create([
  26. 'owner_id' => $this->data['owner_target']['id'],
  27. ]);
  28. $this->data['batches'] = factory(Batch::class, $this->amountOfInRule)->create([
  29. 'owner_id' => $this->data['owner_target']['id'],
  30. ]);
  31. $this->data['batches'][]=factory(Batch::class)->create([
  32. 'owner_id' => $this->data['owner_none_target']['id'],
  33. ]);
  34. }
  35. public function testCreateSuccess()
  36. {
  37. $batches=$this->service->getBatches_shouldProcess($this->data['batches']);
  38. $this->assertEquals($this->amountOfInRule,$batches->count());
  39. }
  40. public function tearDown(): void
  41. {
  42. cache()->flush();
  43. Owner::query()->whereIn('id',[
  44. $this->data['owner_target']['id'],
  45. $this->data['owner_none_target']['id'],
  46. ])->delete();
  47. StationRuleBatch::query()->where('id',$this->data['stationRuleBatch']['id'])->delete();
  48. Batch::query()->whereIn('id',data_get($this->data['batches'],'*.id'))->delete();
  49. parent::tearDown(); // TODO: Change the autogenerated stub
  50. }
  51. }