From ee014302f4853d2d4fb5d49d972963f65296b5d9 Mon Sep 17 00:00:00 2001 From: Luke Policinski Date: Mon, 15 Oct 2018 20:04:02 +0000 Subject: [PATCH] Apply fixes from StyleCI [ci skip] [skip ci] --- src/LaraCart.php | 18 +++++----- src/config/laracart.php | 14 ++++---- tests/ItemsTest.php | 34 +++++++++---------- tests/LaraCartTest.php | 34 +++++++++---------- tests/TotalsTest.php | 74 ++++++++++++++++++++--------------------- 5 files changed, 87 insertions(+), 87 deletions(-) diff --git a/src/LaraCart.php b/src/LaraCart.php index aabc74c..20bd38e 100644 --- a/src/LaraCart.php +++ b/src/LaraCart.php @@ -716,15 +716,15 @@ public function count($withItemQty = true) */ public static function formatMoney($number, $locale = null, $internationalFormat = false, $format = true) { - // When prices in cents needs to be formatted, divide by 100 to allow formatting in whole units - if(config('laracart.prices_in_cents', false) === true && $format){ - $number = $number / 100; - // When prices in cents do not need to be formatted then cast to integer and round the price - } elseif(config('laracart.prices_in_cents', false) === true && !$format) { - $number = (int) round($number); - } else { - $number = number_format($number, 2, '.', ''); - } + // When prices in cents needs to be formatted, divide by 100 to allow formatting in whole units + if (config('laracart.prices_in_cents', false) === true && $format) { + $number = $number / 100; + // When prices in cents do not need to be formatted then cast to integer and round the price + } elseif (config('laracart.prices_in_cents', false) === true && !$format) { + $number = (int) round($number); + } else { + $number = number_format($number, 2, '.', ''); + } if ($format) { setlocale(LC_MONETARY, null); diff --git a/src/config/laracart.php b/src/config/laracart.php index 5fd4fcd..b1dd87b 100644 --- a/src/config/laracart.php +++ b/src/config/laracart.php @@ -40,18 +40,18 @@ */ 'international_format' => false, - /* + /* |-------------------------------------------------------------------------- | If true, lets you supply and retrieve all prices in cents. - | To retrieve the prices as integer in cents, set the $format parameter - | to false for the various price functions. Otherwise you will retrieve - | the formatted price instead. - | Make sure when adding products to the cart, adding coupons, etc, to - | supply the price in cents too. + | To retrieve the prices as integer in cents, set the $format parameter + | to false for the various price functions. Otherwise you will retrieve + | the formatted price instead. + | Make sure when adding products to the cart, adding coupons, etc, to + | supply the price in cents too. |-------------------------------------------------------------------------- | */ - 'prices_in_cents' => false, + 'prices_in_cents' => false, /* |-------------------------------------------------------------------------- diff --git a/tests/ItemsTest.php b/tests/ItemsTest.php index 33c5eea..d948e6d 100644 --- a/tests/ItemsTest.php +++ b/tests/ItemsTest.php @@ -164,23 +164,23 @@ public function testItemPriceAndQty() $this->assertEquals(32.1, $item->subTotal(false, true, false, true)); // return subtotal with tax } - /** - * Test the prices in cents based on the item. - */ - public function testItemPriceInCents() - { - $this->app['config']->set('laracart.prices_in_cents', true); - $item = $this->addItem(3, 1000); - - $this->assertEquals(1000, $item->price(false)); - $this->assertEquals(1070, $item->price(false, false, true)); // return item price with tax - $this->assertEquals(3000, $item->subTotal(false)); - $this->assertEquals(3210, $item->subTotal(false, true, false, true)); // return subtotal with tax - - // Test that floats are converted to int and not rounded in the constructor - $item2 = $this->addItem(3, 1000.55); - $this->assertEquals(1000, $item2->price(false)); - } + /** + * Test the prices in cents based on the item. + */ + public function testItemPriceInCents() + { + $this->app['config']->set('laracart.prices_in_cents', true); + $item = $this->addItem(3, 1000); + + $this->assertEquals(1000, $item->price(false)); + $this->assertEquals(1070, $item->price(false, false, true)); // return item price with tax + $this->assertEquals(3000, $item->subTotal(false)); + $this->assertEquals(3210, $item->subTotal(false, true, false, true)); // return subtotal with tax + + // Test that floats are converted to int and not rounded in the constructor + $item2 = $this->addItem(3, 1000.55); + $this->assertEquals(1000, $item2->price(false)); + } /** * Test removing an item from the cart. diff --git a/tests/LaraCartTest.php b/tests/LaraCartTest.php index 5859b72..a214c52 100644 --- a/tests/LaraCartTest.php +++ b/tests/LaraCartTest.php @@ -60,23 +60,23 @@ public function testFormatMoney() $this->assertEquals('$25.54', $this->laracart->formatMoney('25.544')); } - /** - * Testing the money format function with the prices_in_cents config setting. - */ - public function testFormatMoneyPricesInCents() - { - $this->app['config']->set('laracart.prices_in_cents', true); - - $this->assertEquals('$25.00', $this->laracart->formatMoney(2500)); - $this->assertEquals('USD 25.00', $this->laracart->formatMoney(2500, null, true)); - $this->assertEquals(2500, $this->laracart->formatMoney(2500, null, null, false)); - - $this->assertEquals('$25.01', $this->laracart->formatMoney(2500.55)); - $this->assertEquals('$25.00', $this->laracart->formatMoney(2500.44)); - - $this->assertEquals(2501, $this->laracart->formatMoney(2500.55, null, null, false)); - $this->assertEquals(2500, $this->laracart->formatMoney(2500.44,null, null, false)); - } + /** + * Testing the money format function with the prices_in_cents config setting. + */ + public function testFormatMoneyPricesInCents() + { + $this->app['config']->set('laracart.prices_in_cents', true); + + $this->assertEquals('$25.00', $this->laracart->formatMoney(2500)); + $this->assertEquals('USD 25.00', $this->laracart->formatMoney(2500, null, true)); + $this->assertEquals(2500, $this->laracart->formatMoney(2500, null, null, false)); + + $this->assertEquals('$25.01', $this->laracart->formatMoney(2500.55)); + $this->assertEquals('$25.00', $this->laracart->formatMoney(2500.44)); + + $this->assertEquals(2501, $this->laracart->formatMoney(2500.55, null, null, false)); + $this->assertEquals(2500, $this->laracart->formatMoney(2500.44, null, null, false)); + } /** * Test getting the attributes from the cart. diff --git a/tests/TotalsTest.php b/tests/TotalsTest.php index e40b634..ada45af 100644 --- a/tests/TotalsTest.php +++ b/tests/TotalsTest.php @@ -26,48 +26,48 @@ public function testTotalDiscount() $this->assertEquals(0, $this->laracart->total(false)); } - /** - * Test total discounts when using the pricing_in_cents config setting. - */ - public function testTotalDiscountInCents() - { - $this->app['config']->set('laracart.prices_in_cents', true); - $this->addItem(1, 1000); + /** + * Test total discounts when using the pricing_in_cents config setting. + */ + public function testTotalDiscountInCents() + { + $this->app['config']->set('laracart.prices_in_cents', true); + $this->addItem(1, 1000); - $fixedCoupon = new LukePOLO\LaraCart\Coupons\Fixed( - '10OFF', 1000 - ); + $fixedCoupon = new LukePOLO\LaraCart\Coupons\Fixed( + '10OFF', 1000 + ); - $this->laracart->addCoupon($fixedCoupon); + $this->laracart->addCoupon($fixedCoupon); - $this->assertEquals('$10.00', $this->laracart->totalDiscount()); - $this->assertEquals(1000, $this->laracart->totalDiscount(false)); + $this->assertEquals('$10.00', $this->laracart->totalDiscount()); + $this->assertEquals(1000, $this->laracart->totalDiscount(false)); - $this->assertEquals(0, $this->laracart->total(false)); - } + $this->assertEquals(0, $this->laracart->total(false)); + } /** * Test total taxes. */ public function testTaxTotal() { - $this->addItem(); + $this->addItem(); $this->assertEquals('$0.07', $this->laracart->taxTotal()); $this->assertEquals('0.07', $this->laracart->taxTotal(false)); } - /** - * Test total taxes when using the pricing_in_cents config setting. - */ - public function testTaxTotalInCents() - { - $this->app['config']->set('laracart.prices_in_cents', true); - $this->addItem(1, 100); + /** + * Test total taxes when using the pricing_in_cents config setting. + */ + public function testTaxTotalInCents() + { + $this->app['config']->set('laracart.prices_in_cents', true); + $this->addItem(1, 100); - $this->assertEquals('$0.07', $this->laracart->taxTotal()); - $this->assertEquals(7, $this->laracart->taxTotal(false)); - } + $this->assertEquals('$0.07', $this->laracart->taxTotal()); + $this->assertEquals(7, $this->laracart->taxTotal(false)); + } /** * Test getting all the fees. @@ -107,17 +107,17 @@ public function testTotal() $this->assertEquals('1.07', $this->laracart->total(false)); } - /** - * Test getting the final total (with tax) when using the pricing_in_cents config setting. - */ - public function testTotalInCents() - { - $this->app['config']->set('laracart.prices_in_cents', true); - $this->addItem(1, 100); - - $this->assertEquals('$1.07', $this->laracart->total()); - $this->assertEquals(107, $this->laracart->total(false)); - } + /** + * Test getting the final total (with tax) when using the pricing_in_cents config setting. + */ + public function testTotalInCents() + { + $this->app['config']->set('laracart.prices_in_cents', true); + $this->addItem(1, 100); + + $this->assertEquals('$1.07', $this->laracart->total()); + $this->assertEquals(107, $this->laracart->total(false)); + } /** * Test the taxable fees total.