Make getters public,

Add Test
This commit is contained in:
Patrick Henninger
2020-05-08 20:58:58 +02:00
parent a50767d584
commit 05b99d4e72
2 changed files with 37 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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
*/