| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace Tests\Services\OwnerStoragePriceModelService;
- use App\Owner;
- use App\OwnerReport;
- use App\OwnerStoragePriceModel;
- use App\Services\OwnerStoragePriceModelService;
- use App\Unit;
- use Tests\TestCase;
- class OwnerStoragePriceModelServiceTest extends TestCase
- {
- /** @var OwnerStoragePriceModelService */
- public $service;
- public $data;
- protected function setUp(): void
- {
- parent::setUp();
- $this->service = app(OwnerStoragePriceModelService::class);
- $unit = Unit::query()->where("name","月")->first();
- $units = [];
- if (!$unit){
- $unit = Unit::query()->create([
- "name" => "月",
- "code" => "月"
- ]);
- $units[] = $unit;
- }
- $this->data["units"] = $units;
- $this->data["models"] = [
- factory(OwnerStoragePriceModel::class)->create([
- "minimum_area" => 600, //最低起租面积
- "price" => 80.4, //单价
- "discount_type" => "按单减免", //减免类型
- "discount_value" => 0.1, //减免值
- "unit_id" => 1, //单位ID
- "time_unit_id" => $unit->id, //单位ID
- ])->toArray(),
- factory(OwnerStoragePriceModel::class)->create([
- "minimum_area" => 600, //最低起租面积
- "price" => 80.4, //单价
- "discount_type" => "固定减免", //减免类型
- "discount_value" => 3.6, //减免值
- "unit_id" => 1, //单位ID
- "time_unit_id" => $unit->id, //计时单位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"));
- Unit::destroy(array_column($this->data["units"],"id"));
- parent::tearDown();
- }
- }
|