OwnerBillReportServiceTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Tests\Services\OwnerBillReportService;
  3. use App\Owner;
  4. use App\OwnerBillReport;
  5. use App\Services\OwnerBillReportService;
  6. use App\UserOwnerGroup;
  7. use Tests\TestCase;
  8. class OwnerBillReportServiceTest extends TestCase
  9. {
  10. /** @var OwnerBillReportService */
  11. public $service;
  12. public $data;
  13. protected function setUp(): void
  14. {
  15. parent::setUp();
  16. $this->service = app(OwnerBillReportService::class);
  17. $userOwnerGroup = factory(\App\UserOwnerGroup::class)->create();
  18. $owner = factory(\App\Owner::class)->create([
  19. "user_owner_group_id"=>$userOwnerGroup->id,
  20. ]);
  21. $this->data["owners"] = [$owner->toArray()];
  22. $this->data["userOwnerGroups"] = [$userOwnerGroup->toArray()];
  23. $this->data["models"] = factory(OwnerBillReport::class,3)->create([
  24. "owner_id" => $owner->id,
  25. ])->toArray();
  26. }
  27. /**
  28. * @group customer
  29. */
  30. public function testPaginate()
  31. {
  32. $models = $this->service->paginate(array("paginate"=>5));
  33. $this->assertGreaterThanOrEqual(3,count($models));
  34. $this->assertLessThanOrEqual(5,count($models));
  35. }
  36. /**
  37. * @group customer
  38. */
  39. public function testUpdate(){
  40. $model = $this->data["models"][0];
  41. $result = $this->service->update(["id"=>$model["id"]],[
  42. "difference" => 1000,
  43. ]);
  44. $this->assertEquals(1,$result);
  45. $bill = OwnerBillReport::query()->find($model["id"]);
  46. $this->assertNotNull($bill);
  47. $this->assertEquals(1000,$bill->difference);
  48. }
  49. /**
  50. * @group customer
  51. */
  52. public function testGet(){
  53. $ids = implode(",",array_column($this->data["models"],"owner_id"));
  54. $models = $this->service->get(["owner_id"=>$ids]);
  55. $this->assertGreaterThanOrEqual(3,count($models));
  56. }
  57. protected function tearDown(): void
  58. {
  59. UserOwnerGroup::destroy(array_column($this->data["userOwnerGroups"],"id"));
  60. Owner::destroy(array_column($this->data["owners"],"id"));
  61. OwnerBillReport::destroy(array_column($this->data["models"],"id"));
  62. parent::tearDown();
  63. }
  64. }