/EventSourcing-Example

Primary LanguagePHPApache License 2.0Apache-2.0

Event Sourcing

An example of using EventSourcing pattern in a real project. Implementation of this pattern may contains some flaws.

This is an example of the online shop.

The scenario

  1. User registers himself in the shop
  2. Email is send to to the user's email
  3. User accepts the invitation
  4. User's account is activated
  5. User logs in
  6. User finds a product 'Milk'
  7. User adds 2 pieces of milk to the basket
  8. User finds a product 'Bread'
  9. User adds 1 piece of bread to the basket
  10. User finds a product 'Butter'
  11. User adds 3 pieces of butter to the basket
  12. User changes the quantity of the butter for 1
  13. User removes bread from the basket
  14. User logs out
  15. User logs in
  16. User tries to find a non-existent product called 'Cookies'
  17. User creates the Order
  18. Basket is closed
  19. Send email with the order

System capabilities

  1. Command can cause the series of command executes. E.g. CloseOrderCommand calls CloseBasketCommand and SendEmailCommand.
  2. We want to know what products users searched for and found none.

TODO

  1. DI Container
  2. DBAL
  3. DDD

Tests

Unit Tests

To run unit tests run command:

php vendor/phpunit/phpunit/phpunit --configuration tests/unit-tests/configuration.xml

Behaviour Tests - Behat

To run behat tests execute command:

vendor/bin/behat --config tests/behat/behat.yml 

Integration tests

To run integration tests run command:

php vendor/phpunit/phpunit/phpunit --configuration tests/integration-tests/configuration.xml

Running the example

Run command in console:

php -S localhost:8000

Open the browser and type:

http://localhost:8000/example.php