From cad429ab377b19db67925833bbbe76ef583abb6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kucha=C5=99?= <honza.kuchar@grifart.cz> Date: Sun, 21 Feb 2016 12:20:47 +0100 Subject: [PATCH] Basket (red): Add ability to restore basket from historical events --- tests/BasketTest.phpt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/BasketTest.phpt b/tests/BasketTest.phpt index 044ca1f..45f820d 100644 --- a/tests/BasketTest.phpt +++ b/tests/BasketTest.phpt @@ -61,6 +61,33 @@ class BasketTest extends \Tester\TestCase { Assert::count(3, $basket->getRecordedEvents(), "Double removed product should not generate another event."); } + public function testLoadBasketFromHistory() { + // Arrange + $basketId = new BasketId(Uuid::uuid4()); + $basket = Basket::pickUp($basketId); + $basket->addProduct(new ProductId(Uuid::uuid4()), "Awesome product 2"); + + $events = $basket->getRecordedEvents(); + + // persist events here + // load events here + + // Act + $reconstitutedBasket = Basket::reconstituteFrom( + new AggregateHistory($basketId, $retrievedEvents = $events) + ); + + // Assert + + // When calling reconstituteFrom() it reconstructs object internal state + // BUT does not add events loaded from history into aggregate recorded events + $basket->clearRecordedEvents(); // Important! + + Assert::equal($basket, $reconstitutedBasket, "Original and basket reconstructed from events should be the same"); + + + } + } (new BasketTest())->run(); -- GitLab