OwnerAreaReportServiceTest.php 2.8 KB

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