OwnerAreaReportServiceTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Tests\Services;
  3. use App\OwnerAreaReport;
  4. use App\Services\OwnerAreaReportService;
  5. use Illuminate\Database\Eloquent\Collection;
  6. use Tests\TestCase;
  7. class OwnerAreaReportServiceTest extends TestCase
  8. {
  9. /** @var OwnerAreaReportService */
  10. public $service;
  11. /** @var Collection */
  12. public $data;
  13. protected function setUp(): void
  14. {
  15. parent::setUp();
  16. $this->service = app(OwnerAreaReportService::class);
  17. $this->data = factory(OwnerAreaReport::class,3)->create();
  18. }
  19. public function testPaginate()
  20. {
  21. $models = $this->service->paginate(array("paginate"=>5));
  22. $this->assertGreaterThanOrEqual(3,count($models));
  23. $this->assertLessThanOrEqual(5,count($models));
  24. }
  25. public function testUpdate(){
  26. $model = $this->data[0];
  27. $result = $this->service->update(["id"=>$model->id],[
  28. "accounting_area" => 1000,
  29. ]);
  30. $this->assertEquals(true,$result);
  31. $area = OwnerAreaReport::query()->find($model->id);
  32. $this->assertNotNull($area);
  33. $this->assertEquals(1000,$area->accounting_area);
  34. }
  35. public function testGet(){
  36. $ids = implode(",",array_column($this->data->toArray(),"owner_id"));
  37. $models = $this->service->get(["owner_id"=>$ids]);
  38. $this->assertGreaterThanOrEqual(3,count($models));
  39. }
  40. public function testTruncate(){
  41. OwnerAreaReport::query()->truncate();
  42. $models = OwnerAreaReport::query()->get();
  43. $this->assertCount(0,$models);
  44. }
  45. }