-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Context
We use public private(set) $properties on our aggregates.
These are modified via the apply*-methods.
They just expose the aggregates current state instead of having getters.
Using given/when/then, we can only assert that the right events are created on a given aggregate when something is called.
To cover the correctness of the apply-methods, we also need to assert on the exposed state of the aggregate.
I see two ways of having that:
- Add a new method that can receive a callback, which can run assertions and can
usevariables from the setup scope. - Allow callbacks passed into
then(), which will behave in the same way.
Example
$this
->given(
new ProfileCreated(
ProfileId::fromString('1'),
Email::fromString('hq@patchlevel.de'),
),
)
->when(static fn (Profile $profile) => $profile->visitProfile(ProfileId::fromString('2')))
->then(
new ProfileVisited(ProfileId::fromString('2')),
// passing a callback, requires a union-type for `then()`
static fn (Profile $profile) => $this->assertSame(ProfileId::fromString('1'), $profile->id))
)
// or with a method, but this would break the "standard" given-when-then
->thenCallback(static fn (Profile $profile) => $this->assertSame(ProfileId::fromString('1'), $profile->id)))
;
}Right now PHPUnit assertions can only be ran in the when(), due to the execution phase using after.
Or am i missing something here?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels