From 108ce67d6b4de03c02ac4588dd2e7486eb857f8e Mon Sep 17 00:00:00 2001 From: Lars Klopstra Date: Sun, 13 Jun 2021 17:43:18 +0200 Subject: [PATCH] `hasTax()` for price (#126) * Update Price.php * Update ProductPriceTest.php * Update Price.php * Update Price.php Co-authored-by: Taylor Otwell --- 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..e2f19e0 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 boolean + */ + 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..475b947 100644 --- a/tests/Unit/ProductPriceTest.php +++ b/tests/Unit/ProductPriceTest.php @@ -85,6 +85,13 @@ public function test_it_implements_arrayable_and_jsonable() $this->assertSame($data, $product->jsonSerialize()); $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.