| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace Tests\Services\OwnerBillReportService;
- use App\Owner;
- use App\OwnerBillReport;
- use App\Services\OwnerBillReportService;
- use App\UserOwnerGroup;
- use Tests\TestCase;
- class OwnerBillReportServiceTest extends TestCase
- {
- /** @var OwnerBillReportService */
- public $service;
- public $data;
- protected function setUp(): void
- {
- parent::setUp();
- $this->service = app(OwnerBillReportService::class);
- $userOwnerGroup = factory(\App\UserOwnerGroup::class)->create();
- $owner = factory(\App\Owner::class)->create([
- "user_owner_group_id"=>$userOwnerGroup->id,
- ]);
- $this->data["owners"] = [$owner->toArray()];
- $this->data["userOwnerGroups"] = [$userOwnerGroup->toArray()];
- $this->data["models"] = factory(OwnerBillReport::class,3)->create([
- "owner_id" => $owner->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"]],[
- "difference" => 1000,
- ]);
- $this->assertEquals(1,$result);
- $bill = OwnerBillReport::query()->find($model["id"]);
- $this->assertNotNull($bill);
- $this->assertEquals(1000,$bill->difference);
- }
- /**
- * @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
- {
- UserOwnerGroup::destroy(array_column($this->data["userOwnerGroups"],"id"));
- Owner::destroy(array_column($this->data["owners"],"id"));
- OwnerBillReport::destroy(array_column($this->data["models"],"id"));
- parent::tearDown();
- }
- }
|