From ffc21e69a38f39fe016c1b557609557e8e6e60ea Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Tue, 19 Nov 2024 20:43:52 +0200 Subject: [PATCH 1/2] HP-2212 Fix falling phpunit-legacy Unit tests --- src/bill/Bill.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bill/Bill.php b/src/bill/Bill.php index 6e833f59..a288a494 100755 --- a/src/bill/Bill.php +++ b/src/bill/Bill.php @@ -89,7 +89,12 @@ public function __construct( $this->plan = $plan; $this->charges = $charges; $this->state = $state; - $this->setUsageInterval(UsageInterval::wholeMonth($time)); + $this->initializeWholeMonthUsageInterval(); + } + + public function initializeWholeMonthUsageInterval(): void + { + $this->setUsageInterval(UsageInterval::wholeMonth($this->time)); } /** From 1719b3573918d725be7eec3dd1e4794dc15f4fe7 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 21 Nov 2024 18:08:05 +0200 Subject: [PATCH 2/2] HP-2212 initialize default value for Bill::$usageInterval property --- src/bill/Bill.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/bill/Bill.php b/src/bill/Bill.php index a288a494..81782680 100755 --- a/src/bill/Bill.php +++ b/src/bill/Bill.php @@ -89,12 +89,6 @@ public function __construct( $this->plan = $plan; $this->charges = $charges; $this->state = $state; - $this->initializeWholeMonthUsageInterval(); - } - - public function initializeWholeMonthUsageInterval(): void - { - $this->setUsageInterval(UsageInterval::wholeMonth($this->time)); } /** @@ -116,9 +110,18 @@ public function getUniqueString(): string public function getUsageInterval(): UsageInterval { + if ($this->usageInterval === null) { + $this->initializeWholeMonthUsageInterval(); + } + return $this->usageInterval; } + private function initializeWholeMonthUsageInterval(): void + { + $this->setUsageInterval(UsageInterval::wholeMonth($this->time)); + } + public function calculatePrice() { $quantity = $this->quantity->getQuantity();