| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace Tests\Services\OwnerAreaReportService;
- use App\Owner;
- use App\OwnerAreaReport;
- use App\OwnerStoragePriceModel;
- use App\Services\OwnerAreaReportService;
- use App\Unit;
- use App\UserOwnerGroup;
- use Tests\TestCase;
- class OwnerAreaReportServiceTest extends TestCase
- {
- /** @var OwnerAreaReportService */
- public $service;
- public $data;
- protected function setUp(): void
- {
- parent::setUp();
- $this->service = app(OwnerAreaReportService::class);
- $userOwnerGroup = factory(\App\UserOwnerGroup::class)->create();
- $owner = factory(\App\Owner::class)->create([
- "user_owner_group_id"=>$userOwnerGroup->id,
- ]);
- $unit = factory(Unit::class)->create();
- $ownerStoragePriceModel = factory(\App\OwnerStoragePriceModel::class)->create([
- "unit_id" => $unit->id,
- ]);
- $this->data["owners"] = [$owner->toArray()];
- $this->data["units"] = [$unit->toArray()];
- $this->data["ownerStoragePriceModels"] = [$ownerStoragePriceModel->toArray()];
- $this->data["userOwnerGroups"] = [$userOwnerGroup->toArray()];
- $this->data["models"] = factory(OwnerAreaReport::class,3)->create([
- "owner_id" => $owner->id,
- "owner_storage_price_model_id" => $ownerStoragePriceModel->id,
- "user_owner_group_id" => $userOwnerGroup->id,
- ])->toArray();
- }
- /**
- * @group customer
- */
- public function testPaginate()
- {
- $models = $this->service->paginate(array("paginate"=>5));
- $this->assertGreaterThanOrEqual(3,count($models));
- $this->assertLessThanOrEqual(5,count($models));
- }
- /**
- * @group customer
- */
- public function testUpdate(){
- $model = $this->data["models"][0];
- $result = $this->service->update(["id"=>$model["id"]],[
- "accounting_area" => 1000,
- ]);
- $this->assertEquals(true,$result);
- $area = OwnerAreaReport::query()->find($model["id"]);
- $this->assertNotNull($area);
- $this->assertEquals(1000,$area->accounting_area);
- }
- /**
- * @group customer
- */
- public function testGet(){
- $ids = implode(",",array_column($this->data["models"],"owner_id"));
- $models = $this->service->get(["owner_id"=>$ids]);
- $this->assertGreaterThanOrEqual(3,count($models));
- }
- protected function tearDown(): void
- {
- Owner::destroy(array_column($this->data["owners"],"id"));
- Unit::destroy(array_column($this->data["units"],"id"));
- OwnerStoragePriceModel::destroy(array_column($this->data["ownerStoragePriceModels"],"id"));
- UserOwnerGroup::destroy(array_column($this->data["userOwnerGroups"],"id"));
- OwnerAreaReport::destroy(array_column($this->data["models"],"id"));
- parent::tearDown();
- }
- }
|