From 6d554fabc7b446dcb830e2679d097879d35adef0 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 6 Jan 2022 16:51:22 +0100 Subject: [PATCH] [1.x] Add hasTax (#149) * `hasTax()` for price (#126) * Update Price.php * Update ProductPriceTest.php * Update Price.php * Update Price.php Co-authored-by: Taylor Otwell * Apply fixes from StyleCI Co-authored-by: Lars Klopstra Co-authored-by: Taylor Otwell Co-authored-by: StyleCI Bot --- src/Price.php | 10 ++++++++++ tests/Unit/ProductPriceTest.php | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/src/Price.php b/src/Price.php index 7eab132..5c98a88 100644 --- a/src/Price.php +++ b/src/Price.php @@ -83,6 +83,16 @@ public function tax() return $this->formatAmount((int) ($this->rawTax() * 100)); } + /** + * Determine if the price has tax. + * + * @return bool + */ + public function hasTax() + { + return $this->rawTax() > 0; + } + /** * Get the raw tax amount. * diff --git a/tests/Unit/ProductPriceTest.php b/tests/Unit/ProductPriceTest.php index 7936623..846687d 100644 --- a/tests/Unit/ProductPriceTest.php +++ b/tests/Unit/ProductPriceTest.php @@ -86,6 +86,13 @@ public function test_it_implements_arrayable_and_jsonable() $this->assertSame(json_encode($data), $product->toJson()); } + public function test_it_can_check_if_has_tax() + { + $product = $this->product(); + + $this->assertTrue($product->price()->hasTax()); + } + /** * Get a test product price object. *