CreateTest.php 1020 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Tests\Services\StationTaskService;
  3. use App\Services\StationTaskService;
  4. use App\StationTask;
  5. use Illuminate\Support\Collection;
  6. use Tests\TestCase;
  7. class CreateTest extends TestCase
  8. {
  9. /** @var StationTaskService $service */
  10. private $service;
  11. private $data = [];
  12. public function setUp(): void
  13. {
  14. parent::setUp();
  15. $this->service = app('StationTaskService');
  16. }
  17. public function testCreateSuccess()
  18. {
  19. $amountToCreate=3;
  20. $this->data['stationTasks']=$this->service->create($amountToCreate);
  21. $this->assertEquals(Collection::class,get_class($this->data['stationTasks']));
  22. $this->assertEquals($amountToCreate,$this->data['stationTasks']->count());
  23. $this->assertEquals(StationTask::class,get_class($this->data['stationTasks'][0]));
  24. }
  25. public function tearDown(): void
  26. {
  27. StationTask::query()->whereIn('id',data_get($this->data['stationTasks'],'*.id')??[])->delete();
  28. parent::tearDown();
  29. }
  30. }