OwnerAreaReportServiceTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 testUpdate(){
  41. $model = $this->data["models"][0];
  42. $result = $this->service->update(["id"=>$model["id"]],[
  43. "accounting_area" => 1000,
  44. ]);
  45. $this->assertEquals(true,$result);
  46. $area = OwnerAreaReport::query()->find($model["id"]);
  47. $this->assertNotNull($area);
  48. $this->assertEquals(1000,$area->accounting_area);
  49. }
  50. /**
  51. * @group customer
  52. */
  53. public function testGet(){
  54. $ids = implode(",",array_column($this->data["models"],"owner_id"));
  55. $models = $this->service->get(["owner_id"=>$ids]);
  56. $this->assertGreaterThanOrEqual(3,count($models));
  57. }
  58. protected function tearDown(): void
  59. {
  60. Owner::destroy(array_column($this->data["owners"],"id"));
  61. Unit::destroy(array_column($this->data["units"],"id"));
  62. OwnerStoragePriceModel::destroy(array_column($this->data["ownerStoragePriceModels"],"id"));
  63. UserOwnerGroup::destroy(array_column($this->data["userOwnerGroups"],"id"));
  64. OwnerAreaReport::destroy(array_column($this->data["models"],"id"));
  65. parent::tearDown();
  66. }
  67. }