Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eventsourcing-cqrs-simple-app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Kuchař
eventsourcing-cqrs-simple-app
Commits
cad429ab
Commit
cad429ab
authored
9 years ago
by
Jan Kuchař
Browse files
Options
Downloads
Patches
Plain Diff
Basket (red): Add ability to restore basket from historical events
parent
68cc9427
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/BasketTest.phpt
+27
-0
27 additions, 0 deletions
tests/BasketTest.phpt
with
27 additions
and
0 deletions
tests/BasketTest.phpt
+
27
−
0
View file @
cad429ab
...
...
@@ -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
();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment