ecotoneframework / php-ddd-cqrs-event-sourcing-symfony-laravel-ecotone

Ecotone - ES DDD CQRS PHP Symfony Laravel example
98 stars 22 forks source link

Adding Cli commands for each domains commands tested by CI #2

Closed jclaveau closed 2 years ago

jclaveau commented 2 years ago

This PR targets having an example of continuous integration with Ecotone and Symfony (Still looking for a professional smooth workflow :) ). So it ships:

I post it here in a wip state because I'm stuck: When I run my tests, events are correctly triggered but not async projections. This is not due to Phpunit itself but only to the APP_ENV as this issue occurs when I run a command on an event sourced aggregate only: https://github.com/jclaveau/php-ddd-cqrs-event-sourcing-symfony-ecotone/blob/testing_commands/src/UI/Cli/Ticket/PrepareTicketCliCommand.php

APP_ENV=test console app:prepare-ticket lala lolo

Event sourced Ticket prepare command generates a stream but, contrary to dev env, no asynchronous projection is added to the projections table (It's created but remains empty):

ecotone=# SELECT * FROM projections;
 no |         name          |              position              | state | status | locked_until 
----+-----------------------+------------------------------------+-------+--------+--------------
  1 | last_prepared_tickets | {"App\\Domain\\Ticket\\Ticket": 1} | []    | idle   | 
  2 | unassigned_tickets    | {"App\\Domain\\Ticket\\Ticket": 1} | []    | idle   | 
(2 rows)

ecotone=# \c ecotone_test 
You are now connected to database "ecotone_test" as user "ecotone".
ecotone_test=# SELECT * FROM projections;
 no | name | position | state | status | locked_until 
----+------+----------+-------+--------+--------------
(0 rows)

I wondered if it was due to the fact there is no container running projections in test env but when I try

APP_ENV=test /data/app/bin/console ecotone:es:reset-projection last_prepared_tickets

I get

In ProjectionNotFound.php line 20:

  A projection with name "last_prepared_tickets" could not be found.

Digging in the docs I tried some options without success: https://github.com/jclaveau/php-ddd-cqrs-event-sourcing-symfony-ecotone/blob/testing_commands/src/Infrastructure/EcotoneConfiguration.php

I'm not enough aware of Ecotone to know if this is a usage issue or a bug so let me know if a should open a bug on Ecotone's repo.

Thanks in advance!

dgafka commented 2 years ago

@jclaveau thank you for your work mate :)

Well in case of synchronous projections, they are not set up automatically. I have added a command in 1.10.5, to initialize projection from CLI.

You can call this Command from your tests first in order to prepare the projection. For the demo projection it happens here now: https://github.com/ecotoneframework/php-ddd-cqrs-event-sourcing-symfony-ecotone/blob/master/docker/4-setup-projection.sh

Let me know, if it answers your question :)

jclaveau commented 2 years ago

@dgafka This PR is now ready for a review (My bug was due to a UUID regexp, not to projection initialization, thank you for your reply)

dgafka commented 2 years ago

Feel free to rebase it, if you're still interested in contribution. Closing it for now :)