mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-11 18:54:33 +00:00
Made CartItem implement Jsonable, so it can be cast to json by laravel when building a response
This commit is contained in:
53
tests/CartItemTest.php
Normal file
53
tests/CartItemTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Gloudemans\Tests\Shoppingcart;
|
||||
|
||||
use Orchestra\Testbench\TestCase;
|
||||
use Gloudemans\Shoppingcart\CartItem;
|
||||
use Gloudemans\Shoppingcart\ShoppingcartServiceProvider;
|
||||
|
||||
class CartItemTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Set the package service provider.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return array
|
||||
*/
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [ShoppingcartServiceProvider::class];
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_be_cast_to_an_array()
|
||||
{
|
||||
$cartItem = new CartItem(1, 'Some item', 10.00, ['size' => 'XL', 'color' => 'red']);
|
||||
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'name' => 'Some item',
|
||||
'price' => 10.00,
|
||||
'rowId' => '07d5da5550494c62daf9993cf954303f',
|
||||
'qty' => null,
|
||||
'options' => [
|
||||
'size' => 'XL',
|
||||
'color' => 'red'
|
||||
],
|
||||
'tax' => 0,
|
||||
'subtotal' => 0,
|
||||
], $cartItem->toArray());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_be_cast_to_json()
|
||||
{
|
||||
$cartItem = new CartItem(1, 'Some item', 10.00, ['size' => 'XL', 'color' => 'red']);
|
||||
|
||||
$this->assertJson($cartItem->toJson());
|
||||
|
||||
$json = '{"rowId":"07d5da5550494c62daf9993cf954303f","id":1,"name":"Some item","qty":null,"price":10,"options":{"size":"XL","color":"red"},"tax":0,"subtotal":0}';
|
||||
|
||||
$this->assertEquals($json, $cartItem->toJson());
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,6 @@ class CartTest extends TestCase
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/** @test */
|
||||
public function it_has_a_default_instance()
|
||||
{
|
||||
@@ -489,7 +488,7 @@ class CartTest extends TestCase
|
||||
'price' => 10.00,
|
||||
'tax' => 2.10,
|
||||
'subtotal' => 10.0,
|
||||
'options' => new CartItemOptions,
|
||||
'options' => [],
|
||||
],
|
||||
'370d08585360f5c568b18d1f2e4ca1df' => [
|
||||
'rowId' => '370d08585360f5c568b18d1f2e4ca1df',
|
||||
@@ -499,7 +498,7 @@ class CartTest extends TestCase
|
||||
'price' => 10.00,
|
||||
'tax' => 2.10,
|
||||
'subtotal' => 10.0,
|
||||
'options' => new CartItemOptions,
|
||||
'options' => [],
|
||||
]
|
||||
], $content->toArray());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user