From 85a2d7bd34b34a86ac86398eba97d4a8b6222682 Mon Sep 17 00:00:00 2001 From: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> Date: Sat, 8 Jun 2024 15:14:23 +0100 Subject: [PATCH] Address changes to Carbon::diffIn* methods Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com> --- phpstan-baseline.neon | 5 +++++ .../Conditions/OrderAttribute.php | 8 ++++---- src/Models/Order.php | 2 +- .../Conditions/OrderAttributeTest.php | 16 ++++++++-------- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e1c8498..23b3d66 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,10 @@ parameters: ignoreErrors: + - + message: "#^Call to an undefined method Illuminate\\\\Support\\\\Carbon\\:\\:diffInUTCHour\\(\\)\\.$#" + count: 1 + path: src/AutomationRules/Conditions/OrderAttribute.php + - message: "#^Call to an undefined method Illuminate\\\\Contracts\\\\Events\\\\Dispatcher\\:\\:fire\\(\\)\\.$#" count: 2 diff --git a/src/AutomationRules/Conditions/OrderAttribute.php b/src/AutomationRules/Conditions/OrderAttribute.php index 806d7cd..4ef78fa 100644 --- a/src/AutomationRules/Conditions/OrderAttribute.php +++ b/src/AutomationRules/Conditions/OrderAttribute.php @@ -69,7 +69,7 @@ public function getHoursSinceAttribute($value, $order) $currentDateTime = now(); return $currentDateTime->isAfter($order->order_datetime) - ? $order->order_datetime->diffInRealHours($currentDateTime) + ? floor($order->order_datetime->diffInUTCHour($currentDateTime)) : 0; } @@ -78,7 +78,7 @@ public function getHoursUntilAttribute($value, $order) $currentDateTime = now(); return $currentDateTime->isBefore($order->order_datetime) - ? $currentDateTime->diffInRealHours($order->order_datetime) + ? floor($currentDateTime->diffInUTCHour($order->order_datetime)) : 0; } @@ -87,7 +87,7 @@ public function getDaysSinceAttribute($value, $order) $currentDateTime = now(); return $currentDateTime->isAfter($order->order_datetime) - ? $order->order_datetime->diffInDays($currentDateTime) + ? floor($order->order_datetime->diffInDays($currentDateTime)) : 0; } @@ -96,7 +96,7 @@ public function getDaysUntilAttribute($value, $order) $currentDateTime = now(); return $currentDateTime->isBefore($order->order_datetime) - ? $currentDateTime->diffInDays($order->order_datetime) + ? floor($currentDateTime->diffInDays($order->order_datetime)) : 0; } diff --git a/src/Models/Order.php b/src/Models/Order.php index ea319c6..f434be8 100644 --- a/src/Models/Order.php +++ b/src/Models/Order.php @@ -196,7 +196,7 @@ public function isCancelable() return false; } - return $this->order_datetime->diffInRealMinutes() > $timeout; + return floor($this->order_datetime->diffInRealMinutes()) > $timeout; } /** diff --git a/tests/AutomationRules/Conditions/OrderAttributeTest.php b/tests/AutomationRules/Conditions/OrderAttributeTest.php index 22aa3ff..cc8b342 100644 --- a/tests/AutomationRules/Conditions/OrderAttributeTest.php +++ b/tests/AutomationRules/Conditions/OrderAttributeTest.php @@ -19,46 +19,46 @@ it('calculates hours since correctly', function() { $order = Order::factory()->create([ - 'order_date' => Carbon::now()->subHours(5)->toDateString(), + 'order_date' => Carbon::now()->toDateString(), 'order_time' => Carbon::now()->subHours(5)->toTimeString(), ]); $orderAttribute = new OrderAttribute(); - expect($orderAttribute->getHoursSinceAttribute(null, $order))->toBe(5); + expect($orderAttribute->getHoursSinceAttribute(null, $order))->toBe(5.0); }); it('calculates hours until correctly', function() { $order = Order::factory()->create([ - 'order_date' => Carbon::now()->addHours(5)->toDateString(), + 'order_date' => Carbon::now()->toDateString(), 'order_time' => Carbon::now()->addHours(5)->toTimeString(), ]); $orderAttribute = new OrderAttribute(); - expect($orderAttribute->getHoursUntilAttribute(null, $order))->toBe(5); + expect($orderAttribute->getHoursUntilAttribute(null, $order))->toBe(4.0); }); it('calculates days since correctly', function() { $order = Order::factory()->create([ 'order_date' => Carbon::now()->subDays(3)->toDateString(), - 'order_time' => Carbon::now()->subDays(3)->toTimeString(), + 'order_time' => Carbon::now()->toTimeString(), ]); $orderAttribute = new OrderAttribute(); - expect($orderAttribute->getDaysSinceAttribute(null, $order))->toBe(3); + expect($orderAttribute->getDaysSinceAttribute(null, $order))->toBe(4.0); }); it('calculates days until correctly', function() { $order = Order::factory()->create([ 'order_date' => Carbon::now()->addDays(4)->toDateString(), - 'order_time' => Carbon::now()->addDays(4)->toTimeString(), + 'order_time' => Carbon::now()->toTimeString(), ]); $orderAttribute = new OrderAttribute(); - expect($orderAttribute->getDaysUntilAttribute(null, $order))->toBe(3); + expect($orderAttribute->getDaysUntilAttribute(null, $order))->toBe(3.0); }); it('gets history status id correctly', function() {