mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-11 18:54:33 +00:00
Make getters public,
Add Test
This commit is contained in:
@@ -890,7 +890,7 @@ class Cart
|
||||
*
|
||||
* @return \Carbon\Carbon|null
|
||||
*/
|
||||
private function createdAt()
|
||||
public function createdAt()
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
@@ -900,7 +900,7 @@ class Cart
|
||||
*
|
||||
* @return \Carbon\Carbon|null
|
||||
*/
|
||||
private function updatedAt()
|
||||
public function updatedAt()
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Gloudemans\Tests\Shoppingcart;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Gloudemans\Shoppingcart\Cart;
|
||||
use Gloudemans\Shoppingcart\CartItem;
|
||||
use Gloudemans\Shoppingcart\ShoppingcartServiceProvider;
|
||||
@@ -870,6 +871,40 @@ class CartTest extends TestCase
|
||||
Event::assertDispatched('cart.stored');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_can_store_and_retrieve_cart_from_the_database_with_correct_timestamps()
|
||||
{
|
||||
$this->artisan('migrate', [
|
||||
'--database' => 'testing',
|
||||
]);
|
||||
|
||||
Event::fake();
|
||||
|
||||
$cart = $this->getCart();
|
||||
|
||||
|
||||
|
||||
$cart->add(new BuyableProduct());
|
||||
|
||||
$beforeStore = Carbon::now();
|
||||
|
||||
/* Sleep as database does not store ms */
|
||||
sleep(1);
|
||||
|
||||
$cart->store($identifier = 123);
|
||||
|
||||
sleep(1);
|
||||
|
||||
$afterStore = Carbon::now();
|
||||
|
||||
$cart->restore($identifier);
|
||||
|
||||
$this->assertTrue($beforeStore->lessThanOrEqualTo($cart->createdAt()) && $afterStore->greaterThanOrEqualTo($cart->createdAt()));
|
||||
$this->assertTrue($beforeStore->lessThanOrEqualTo($cart->updatedAt()) && $afterStore->greaterThanOrEqualTo($cart->updatedAt()));
|
||||
|
||||
Event::assertDispatched('cart.stored');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user