mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-23 23:51:25 +00:00
Removed Cart facade from coverage (does not provide a public inteterface)
Exclude migrations from coverage Added tests for InstanceIdentifier Added InstanceIdentifier support to store, restore and merge Added weight to CanBeBought trait Excluded CanBeBought trait from coverage temporarily
This commit is contained in:
@@ -15,6 +15,7 @@ use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Gloudemans\Shoppingcart\ShoppingcartServiceProvider;
|
||||
use Gloudemans\Tests\Shoppingcart\Fixtures\ProductModel;
|
||||
use Gloudemans\Tests\Shoppingcart\Fixtures\BuyableProduct;
|
||||
use Gloudemans\Tests\Shoppingcart\Fixtures\Identifiable;
|
||||
|
||||
class CartTest extends TestCase
|
||||
{
|
||||
@@ -1066,6 +1067,33 @@ class CartTest extends TestCase
|
||||
$this->assertEquals('500.00', $cart->weight(2));
|
||||
$this->assertEquals(500.00, $cart->weightFloat());
|
||||
$this->assertEquals(500.00, $cartItem->weightTotal);
|
||||
$this->assertEquals('250.00', $cartItem->weight(2));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function cart_can_create_and_restore_from_instance_identifier()
|
||||
{
|
||||
$this->artisan('migrate', [
|
||||
'--database' => 'testing',
|
||||
]);
|
||||
|
||||
Event::fake();
|
||||
|
||||
$identifier = new Identifiable('User1', 0);
|
||||
$cart = $this->getCart();
|
||||
|
||||
$cart->instance($identifier);
|
||||
$this->assertEquals('User1', $cart->currentInstance());
|
||||
|
||||
$cart->add(new BuyableProduct(1, 'First item', 10.00, 250), 2);
|
||||
$this->assertItemsInCart(2, $cart);
|
||||
|
||||
$cart->store($identifier);
|
||||
$cart->destroy();
|
||||
$this->assertItemsInCart(0, $cart);
|
||||
|
||||
$cart->restore($identifier);
|
||||
$this->assertItemsInCart(2, $cart);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
51
tests/Fixtures/Identifiable.php
Normal file
51
tests/Fixtures/Identifiable.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Gloudemans\Tests\Shoppingcart\Fixtures;
|
||||
|
||||
use Gloudemans\Shoppingcart\Contracts\InstanceIdentifier;
|
||||
|
||||
class Identifiable implements InstanceIdentifier
|
||||
{
|
||||
/**
|
||||
* @var int|string
|
||||
*/
|
||||
private $identifier;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $discountRate;
|
||||
|
||||
/**
|
||||
* BuyableProduct constructor.
|
||||
*
|
||||
* @param int|string $id
|
||||
* @param string $name
|
||||
* @param float $price
|
||||
*/
|
||||
public function __construct($identifier = 'identifier', $discountRate = 0)
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
$this->discountRate = $discountRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unique identifier to load the Cart from
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
public function getInstanceIdentifier($options = null)
|
||||
{
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unique identifier to load the Cart from
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
public function getInstanceGlobalDiscount($options = null)
|
||||
{
|
||||
return $this->discountRate;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user