| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace Tests\Services\OwnerStoragePriceModelService;
- use App\Owner;
- use App\OwnerReport;
- use App\OwnerStoragePriceModel;
- use App\Services\OwnerStoragePriceModelService;
- use Tests\TestCase;
- class OwnerStoragePriceModelServiceTest extends TestCase
- {
- /** @var OwnerStoragePriceModelService */
- public $service;
- public $data;
- protected function setUp(): void
- {
- parent::setUp();
- $this->service = app(OwnerStoragePriceModelService::class);
- $this->data["models"] = [
- factory(OwnerStoragePriceModel::class)->create([
- "minimum_area" => 600, //最低起租面积
- "price" => 80.4, //单价
- "discount_type" => "按单减免", //减免类型
- "discount_value" => 0.1, //减免值
- "unit_id" => 1, //单位ID
- ])->toArray(),
- factory(OwnerStoragePriceModel::class)->create([
- "minimum_area" => 600, //最低起租面积
- "price" => 80.4, //单价
- "discount_type" => "固定减免", //减免类型
- "discount_value" => 3.6, //减免值
- "unit_id" => 1, //单位ID
- ])->toArray(),
- ];
- $this->data["owners"] = [
- factory(Owner::class)->create(["user_owner_group_id"=>1])->toArray()
- ];
- $this->data["reports"] = [
- factory(OwnerReport::class)->create([
- "owner_id" => $this->data["owners"][0]["id"],
- "owner_bill_report_id" =>1,
- "total" => 1587,
- "counting_month" => "2020-10-10"
- ])->toArray()
- ];
- }
- /**
- * @group customer
- */
- public function testCalculationAmount()
- {
- $model = OwnerStoragePriceModel::query()->find($this->data["models"][0]["id"]);
- $result = $this->service->calculationAmount($model,548.98,$this->data["owners"][0]["id"],"2020-10-10");
- $this->assertEquals(48081.3,$result);
- $model = OwnerStoragePriceModel::query()->find($this->data["models"][1]["id"]);
- $result = $this->service->calculationAmount($model,548.98,$this->data["owners"][0]["id"],"2020-10-10");
- $this->assertEquals(48236.4,$result);
- }
- public function tearDown(): void
- {
- OwnerStoragePriceModel::destroy(array_column($this->data["models"],"id"));
- Owner::destroy(array_column($this->data["owners"],"id"));
- OwnerReport::destroy(array_column($this->data["reports"],"id"));
- parent::tearDown();
- }
- }
|