-
Whenever a projector or reactor is added to the projectionist, it's always immediately resolved from the container: class Projectionist
{
public function addProjector($projector): Projectionist
{
if (is_string($projector)) {
$projector = app($projector);
} This approach has a few down sides:
Consider the following test case: /** @test */
public function test_pay_payment()
{
FakeOrderPaymentPaidReactor::fake();
Carbon::setTestNow('2020-01-01');
$payment = PaymentAggregateFactory::new()->create();
$payment = (new PayPayment)($payment);
$this->assertTrue($payment->state->equals(PaidPaymentState::class));
$this->assertTrue(Carbon::create('2020-01-01')->eq($payment->paid_at));
} This integration test will test for quite a lot of things. One side effect of a payment being paid though is that an invoice is generated with browsershot in the
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
I'm ok with instantiating them when they are used if that would solve these problems. |
Beta Was this translation helpful? Give feedback.
-
Fixed with Projectionist::fake() in v5. |
Beta Was this translation helpful? Give feedback.
-
Edit: After revisiting Brendts last comment. And checking the codebase, we should be able to remove the temporary fix. Created a PR for that: #312 I'm running into issues with the current solution (resolving handlers within the I've created a zero-downtime-replay package. To enable a replay in the background, to a copy of the db. So that the application doesn't need downtime while replaying a large event stream. In order for this to work, the projector needs to know if it's replaying to the live projection or a background projection. For this, a property is set on the instantiated projector. Of course, re-resolving the projector from the container resets its state, breaking the package. I've tried to find a work-around on this, but can't find a good one. Curious, how would you guys resolve this issue? To give my 2 cents around the initial issue: I think the "testing" problem is either a sign that there is too much coupling in the package. Or that you try to test too much at once. I'd disable projectors when testing the aggregate root. And I'd test a projector in isolation (call the handle method with the event you want the projector to handle). |
Beta Was this translation helpful? Give feedback.
Fixed with Projectionist::fake() in v5.