-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scenario should allow for setting arbitrary ID for given events. #18
Scenario should allow for setting arbitrary ID for given events. #18
Conversation
👍 |
Add aggreateId as part of the scenario
Merged simensen#1 from @wjzijderveld. It helped make this whole thing more explicit and still leaves it BC. My only concern about this is that it means someone can call this and might expect that it works but it won't: $this->scenario
->given($eventsBefore)
->withAggregateId($userId)
->when($command)
->then($eventsAfter); |
} | ||
|
||
/** | ||
* @param array $events | ||
* @param string $id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can be removed again :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
This pull made us realize an inconsistency in our test setup. According to AggregateRoot Though this is a minor BC break in the Scenario all tests still run - if you run What is your opinion on this? |
@fritsjanb I'm wondering if we can remove the requirement for getId on AggregateRoot altogether. I haven't tried implementing this yet, but this is what I have in mind: https://gist.github.com/simensen/d982fac5550d3b5f8698 Basically, adding something like |
@simensen Short answer: could you create a separate issue for this? Long answer: The fact remains that your aggregate needs a function to expose its identity. There is only one reason for this: it allows us to store the events. Of course you could move the responsibility for this to the RepositoryInterface (I do think this is an elegant solution), but you would still have to implement a function in your True, it allows you to expose a Regarding the extending of the Repository: this is not entirely true. In our application we do in fact extend it (for typehinting purposes and it makes testing easier), but at this point it is not yet required. At the moment our repositories look like this:
but you could just instantiate an Anyways, it would be nice if you could create a separate issue for this :) |
Moved the discussion about the aggregate root here: #34 |
👍, nice API :) |
@kelvinj could you still change the default int 1 to a '1'? :) |
@fritsjanb The most recent change to #19 makes it so that ID can be an int, a string, or an object that implements __toString. I think that means that the default value in this case can be left at 1 (int)? Let me know if you disagree. FWIW, I think it is a fine assumption that someone might want to use an int for their ID. As far as I know, (string) 5 === '5' so I think this is a safe assumption. |
👍 |
@simensen agreed with leaving 1 as an int Merging! |
…-testing-scenario Scenario should allow for setting arbitrary ID for given events.
@fritsjanb Yay! Awesome. :) |
Here is my use case:
Without being able to specify an ID for the given() events, I was getting an error from the event store saying that no stream could be found for the given ID.
There was already notes in the class saying that maybe hardcoding the ID to 1 wasn't all that good of an idea. :)
It might be more consistent to not have a default ID and to require the aggregate root ID to be the first argument instead. I implemented it this way first as it would be minimal impact on existing code and as a proof of concept.