yourwebmaker / cqrs.nu-php

This is a working example of CQRS/ES in PHP. It's based on the well-known C# CQRS.nu tutorial. It uses EventSauce, but you can use any other EventSourcing package.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A potential bug with Tab::$outstandingDrinks, and maybe other collections too

davidwilliams7436 opened this issue Β· comments

I'm new to ES and I'm trying to learn more about it using your project (btw, thanks πŸ‘ ).

While debugging the code trying to figure out how the AggregateRootBehaviour::reconstituteFromEvents() (from EventSauce) actually works, I've notice a strange behaviour of the Cafe\Domain\Tab\Tab object: it seems to keep only the last "outstanding drink", ignoring all previously added. The same probably applies to the $outstandingFood collection as well.

Steps to reproduce:

  1. Open a tab
  2. Order one drink, submit with the Place Order button
  3. Order another drink, submit (this is important, must be done as a new event)

At this point you should have 3 records in the aggregate_tab db table: one cafe.domain.tab.events.tab_opened and two cafe.domain.tab.events.drinks_ordered.

And here I did my silly debugging by var_dumping the $tab variable right after this line. Turned out the $outstandingDrinks property has only one item (a drink from the second event). I would expect to see both drinks here, unless I'm completely missing the point how this should work.
The reason why it happens is that we have two events of the cafe.domain.tab.events.drinks_ordered type and they both are applied by the reconstituteFromEvents() method. However, the Tab::applyDrinksOrdered() method, before doing anything else, sets the $outstandingDrinks property to an empty collection (here), clearing any existing items.
After commenting this line both drinks appear in the $outstandingDrinks collection.

Now I'm a bit confused because this line was added quite long ago (over a year ago, if I see not mistaken). Is it possible that this hasn't been noticed before?

As I wrote at the beginning, I'm just trying to get a grasp on how ES works so it's quite possible that I'm just talking stupid things here.
Can someone verify this, please?

Hey @davidwilliams7436

I'm stuck an issue while installing the project locally due to my composer version (2.3.*). I think I will need to upgrade the SF version and it will work. After that I will investigate your issue, but I think it's a bug.

Get back to you tomorrow or so ;)

Thanks for the interest in my project ;) Hope you're learning something with it. That was the main reason the project was developed :) .

And sorry for my late reply. I simply deactivate all notifications hahahaha

Hi @davidwilliams7436 . It took a while, but it's fixed now. Thanks for your report!