Skip to content

Commit

Permalink
bad sub totals , added tests for cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepolo committed Dec 4, 2015
1 parent 4db7724 commit 2352485
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
28 changes: 14 additions & 14 deletions build/logs/clover.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1447774743">
<project timestamp="1447774743">
<coverage generated="1449230609">
<project timestamp="1449230609">
<package name="LukePOLO\LaraCart">
<file name="/home/vagrant/Code/MINT/vendor/lukepolo/laracart/src/Cart.php">
<class name="Cart" namespace="LukePOLO\LaraCart" fullPackage="LukePOLO" package="LukePOLO">
Expand Down Expand Up @@ -82,8 +82,8 @@
<line num="180" type="method" name="subTotal" crap="2" count="4"/>
<line num="182" type="stmt" count="4"/>
<line num="184" type="stmt" count="4"/>
<line num="185" type="stmt" count="2"/>
<line num="186" type="stmt" count="2"/>
<line num="185" type="stmt" count="3"/>
<line num="186" type="stmt" count="3"/>
<line num="188" type="stmt" count="4"/>
<line num="200" type="method" name="subItemsTotal" crap="5" count="4"/>
<line num="202" type="stmt" count="4"/>
Expand All @@ -96,16 +96,16 @@
<line num="211" type="stmt" count="2"/>
<line num="212" type="stmt" count="2"/>
<line num="214" type="stmt" count="4"/>
<line num="224" type="method" name="getDiscount" crap="2.04" count="2"/>
<line num="227" type="stmt" count="2"/>
<line num="229" type="stmt" count="2"/>
<line num="224" type="method" name="getDiscount" crap="2.04" count="3"/>
<line num="227" type="stmt" count="3"/>
<line num="229" type="stmt" count="3"/>
<line num="230" type="stmt" count="0"/>
<line num="231" type="stmt" count="0"/>
<line num="233" type="stmt" count="2"/>
<line num="234" type="stmt" count="2"/>
<line num="235" type="stmt" count="2"/>
<line num="236" type="stmt" count="2"/>
<line num="238" type="stmt" count="2"/>
<line num="233" type="stmt" count="3"/>
<line num="234" type="stmt" count="3"/>
<line num="235" type="stmt" count="3"/>
<line num="236" type="stmt" count="3"/>
<line num="238" type="stmt" count="3"/>
<metrics loc="240" ncloc="154" classes="1" methods="10" coveredmethods="7" conditionals="0" coveredconditionals="0" statements="64" coveredstatements="59" elements="74" coveredelements="66"/>
</file>
<file name="/home/vagrant/Code/MINT/vendor/lukepolo/laracart/src/CartSubItem.php">
Expand Down Expand Up @@ -247,8 +247,8 @@
<line num="343" type="stmt" count="1"/>
<line num="350" type="method" name="getCoupons" crap="1" count="1"/>
<line num="352" type="stmt" count="1"/>
<line num="362" type="method" name="findCoupon" crap="1" count="5"/>
<line num="364" type="stmt" count="5"/>
<line num="362" type="method" name="findCoupon" crap="1" count="6"/>
<line num="364" type="stmt" count="6"/>
<line num="373" type="method" name="addCoupon" crap="2" count="3"/>
<line num="375" type="stmt" count="3"/>
<line num="376" type="stmt" count="3"/>
Expand Down
2 changes: 1 addition & 1 deletion src/CartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function update($key, $value)
*/
public function subTotal($tax = false, $format = true, $withDiscount = true)
{
$total = ($this->getPrice($tax, false) + $this->subItemsTotal($tax, false)) * $this->qty;
$total = $this->getPrice($tax, false) + $this->subItemsTotal($tax, false);

if ($withDiscount) {
$total -= $this->getDiscount(false);
Expand Down
21 changes: 16 additions & 5 deletions tests/LaraCartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public function testTaxTotal()

public function testSubTotal()
{
$this->laracart->add(
$item = $this->laracart->add(
'1',
'Testing Item',
1,
Expand All @@ -480,6 +480,10 @@ public function testSubTotal()

$this->assertEquals('$24.00', $this->laracart->subTotal());
$this->assertEquals('24.00', $this->laracart->subTotal(false, false));

$item->qty = 5;

$this->assertEquals('120.00', $this->laracart->subTotal(false, false));
}

public function testTotal()
Expand All @@ -502,19 +506,26 @@ public function testTotal()


// TODO - Test taxable fees
$item = $this->laracart->add(
$notTaxedItem = $this->laracart->add(
'1',
'Testing Item',
1,
'1.00',
'2.00',
[
'b_test' => 'option_1',
'a_test' => 'option_2',
],
false
);

$this->assertEquals('$2.07', $this->laracart->total());
$this->assertEquals('2.07', $this->laracart->total(false));
$this->assertEquals('$3.07', $this->laracart->total());
$this->assertEquals('3.07', $this->laracart->total(false));

$item->qty = 5;

$this->assertEquals('7.00', $this->laracart->subTotal(false, false));


$this->assertEquals('7.35', $this->laracart->total(false));
}
}

0 comments on commit 2352485

Please sign in to comment.