Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
[ci skip] [skip ci]
  • Loading branch information
lukepolo authored and StyleCIBot committed Oct 15, 2018
1 parent bd888f3 commit ee01430
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 87 deletions.
18 changes: 9 additions & 9 deletions src/LaraCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/config/laracart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,

/*
|--------------------------------------------------------------------------
Expand Down
34 changes: 17 additions & 17 deletions tests/ItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 17 additions & 17 deletions tests/LaraCartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
74 changes: 37 additions & 37 deletions tests/TotalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ee01430

Please sign in to comment.