| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace Tests\Services;
- use App\OwnerBillReport;
- use App\Services\OwnerBillReportService;
- use Illuminate\Database\Eloquent\Collection;
- use Tests\TestCase;
- class OwnerBillReportServiceTest extends TestCase
- {
- /** @var OwnerBillReportService */
- public $service;
- /** @var Collection */
- public $data;
- protected function setUp(): void
- {
- parent::setUp();
- $this->service = app(OwnerBillReportService::class);
- $this->data = factory(OwnerBillReport::class,3)->create();
- }
- public function testPaginate()
- {
- $models = $this->service->paginate(array("paginate"=>5));
- $this->assertGreaterThanOrEqual(3,count($models));
- $this->assertLessThanOrEqual(5,count($models));
- }
- public function testUpdate(){
- $model = $this->data[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);
- }
- public function testGet(){
- $ids = implode(",",array_column($this->data->toArray(),"owner_id"));
- $models = $this->service->get(["owner_id"=>$ids]);
- $this->assertGreaterThanOrEqual(3,count($models));
- }
- public function testTruncate(){
- OwnerBillReport::query()->truncate();
- $models = OwnerBillReport::query()->get();
- $this->assertCount(0,$models);
- }
- }
|