Adicionando Event Sourced Aggregates#31
Adicionando Event Sourced Aggregates#31lucianoqueiroz wants to merge 83 commits intoPHPeste:masterfrom
Conversation
|
|
||
| function it_should_return_datetimes_objects_on_start_and_end_methods() | ||
| { | ||
| $this->beConstructedThrough('fromStartAndEnd', ['2016-01-01', '2016-04-01']); |
There was a problem hiding this comment.
same as above, DateTimeImmutable objects please.
| function it_should_return_datetimes_objects_on_start_and_end_methods() | ||
| { | ||
| $this->beConstructedThrough('fromStartAndEnd', ['2016-01-01', '2016-04-01']); | ||
| $this->start()->shouldReturnAnInstanceOf(\DateTime::class); |
There was a problem hiding this comment.
Changed to DateTimeImmutable!
| { | ||
| $this->beConstructedThrough('fromStartAndEnd', ['2016-01-01', '2016-04-01']); | ||
| $this->start()->shouldReturnAnInstanceOf(\DateTime::class); | ||
| $this->end()->shouldReturnAnInstanceOf(\DateTime::class); |
There was a problem hiding this comment.
nop. Remember, less state changes you have, better you can trust the system. make it DateTimeImmutable
There was a problem hiding this comment.
Changed to DateTimeImmutable! 👍
| use Conticket\Model\Events\Event\TicketWasAdded; | ||
| use Assert\Assertion; | ||
|
|
||
| class Event extends AggregateRoot |
| private $aggregateId; | ||
| private $name; | ||
| private $description; | ||
| private $tickets = []; |
There was a problem hiding this comment.
Do not use an array, use a collection.
| Assertion::notEmpty($end, "End date is required."); | ||
|
|
||
| $start = new \DateTime($start); | ||
| $end = new \DateTime($end); |
| return new self($start, $end); | ||
| } | ||
|
|
||
| public function start() |
| return $this->start; | ||
| } | ||
|
|
||
| public function end() |
| return $this->end; | ||
| } | ||
|
|
||
| public function expiresOn(){} |
|
|
||
| public static function toString($statusCode) | ||
| { | ||
| return isset(self::$strings[$statusCode]) ? self::$strings[$statusCode] : null; |
| class EventSpec extends ObjectBehavior | ||
| { | ||
|
|
||
| function let() |
There was a problem hiding this comment.
visibility please, do not follow bad practices
There was a problem hiding this comment.
Those are auto generated objects by PhpSpec 👊
composer.json
Outdated
| "friendsofsymfony/rest-bundle": "^1.7", | ||
| "jms/serializer-bundle": "^1.0", | ||
| "doctrine/doctrine-fixtures-bundle": "^2.2" | ||
| "zendframework/zend-expressive": "^1.0", |
composer.json
Outdated
| "zendframework/zend-expressive": "^1.0", | ||
| "ramsey/uuid": "^2.8", | ||
| "beberlei/assert": "^2.6", | ||
| "prooph/event-sourcing": "~4.0", |
| use PhpSpec\ObjectBehavior; | ||
| use Prophecy\Argument; | ||
|
|
||
| class EventSpec extends ObjectBehavior |
| ]); | ||
| } | ||
|
|
||
| function it_is_initializable() |
|
|
||
| function it_is_initializable() | ||
| { | ||
| $this->shouldHaveType('Conticket\Model\Aggregates\Event\Event'); |
| $this->shouldHaveType('Conticket\Model\Aggregates\Event\Event'); | ||
| } | ||
|
|
||
| function it_should_return_event_id() |
| $this->shouldHaveType('Conticket\Model\Aggregates\Event\TicketLifespan'); | ||
| } | ||
|
|
||
| function it_throws_an_exception_when_start_date_is_greater_than_end_date() |
|
|
||
| class Event extends AggregateRoot | ||
| { | ||
| private $aggregateId; |
| return $this->id() === $userId->id(); | ||
| } | ||
|
|
||
| public function toString() |
There was a problem hiding this comment.
not needed, you have __toString
| return $this->id; | ||
| } | ||
|
|
||
| public function __toString() |
|
|
||
| public function __construct($id = null) | ||
| { | ||
| $this->id = null === $id ? self::fromString(Uuid::uuid4()->toString()) : $id; |
|
|
||
| namespace Conticket\Model\Aggregates\Event; | ||
|
|
||
| class TicketEndDateMustBeGreaterThanStartDateException extends \Exception |
|
|
||
| class TicketEndDateMustBeGreaterThanStartDateException extends \Exception | ||
| { | ||
| public function __construct($message = 'Ticket end date must be greater than start date') |
There was a problem hiding this comment.
do not do it, use named constructors instead
| $ticket->name = $name; | ||
| $this->description = $description; | ||
| $this->status = TicketStatus::INACTIVE; | ||
| return $ticket; |
There was a problem hiding this comment.
missing an empty line above it.
| @@ -43,5 +43,6 @@ public function fromIdAndNameAndDescription(TicketId $id, $name, $description) | |||
| $ticket->name = $name; | |||
| @@ -0,0 +1,82 @@ | |||
| <?php | |||
| /* | |||
| @@ -0,0 +1,29 @@ | |||
| <?php | |||
|
|
|||
| @@ -0,0 +1,55 @@ | |||
| <?php | |||
| /* | |||
| * | ||
| * This software consists of voluntary contributions made by many individuals | ||
| * and is licensed under the MIT license. | ||
| */ |
| $this->id = null === $id ? self::fromString(Uuid::uuid4()->toString()) : $id; | ||
| } | ||
|
|
||
| public static function fromString($id) |
| { | ||
| public static function fromTicketAndNameAndDescription($ticketId, $name, $description) | ||
| { | ||
| return self::occur($ticketId->toString(), [ |
| { | ||
| return self::occur($ticketId->toString(), [ | ||
| 'name' => $name, | ||
| 'description' => $description |
| ]); | ||
| } | ||
|
|
||
| public function name() |
| return $this->payload['name']; | ||
| } | ||
|
|
||
| public function description() |
|
|
||
| public function name() | ||
| { | ||
| return $this->payload['name']; |
There was a problem hiding this comment.
do not leave it on the payload, move it to a private variable :D
There was a problem hiding this comment.
what's the problem with the payload? i like him 🕶
|
I'm wondering if we can drop php |
|
The project main idea is to apply new thought and technologies. So...7.1 for sure. |
|
@lucianoqueiroz welcome to @malukenho's review!!!!! hahahaha |
|
@lucianoqueiroz Why didn't you delete old files? We are working with a VCS. ;) |
|
@abdala this guy is a pain in the ass 😩 |
|
@abdala ok, i deleted entire ApiBundle 😄 i was using it to guide the modelling |
| use Prophecy\Argument; | ||
| use Conticket\Model\Aggregates\Event\TicketEndDateMustBeGreaterThanStartDateException; | ||
|
|
||
|
|
There was a problem hiding this comment.
too much space in here, remove one line
|
|
||
| final class TicketLifespanSpec extends ObjectBehavior | ||
| { | ||
| public function it_is_initializable() |
There was a problem hiding this comment.
man, this Spec classes get broken when we set the return to :void
| $this->value = $value; | ||
| } | ||
|
|
||
| public static function fromAmount(string $amount, string $code = self::CURRENCY_DEFAULT) |
| { | ||
| public static function fromTicketAndStartDateAndEndDate( | ||
| Ticket $ticket, \DateTimeImmutable $start, \DateTimeImmutable $end | ||
| ) : self |
There was a problem hiding this comment.
man, "cs" to me is counter strike... what do you mean? 😆
There was a problem hiding this comment.
i got what means above hehe
|
guys, i have to perform some functional tests yet to assure the classes are working well together. I made the previous commit to show how de ticket modeling is going on. other thing i should ask is if we can merge some properties into other value objects for example (price + quantity + lifespam) = TicketDetail or TicketInfo could be good? i also would like to discuss about (name + description) I'm usually getting this kinds of properties in only one like TicketCover or TicketHeadline, TicketBody. Some concept of something that is used to illustrate/inform the user about the Ticket. |
|
|
||
| final class Event extends AggregateRoot | ||
| { | ||
| private $aggregateId; |
There was a problem hiding this comment.
missing dockblock, mainly for IDE hint
| final class Event extends AggregateRoot | ||
| { | ||
| private $aggregateId; | ||
| private $name; |
| { | ||
| private $aggregateId; | ||
| private $name; | ||
| private $description; |
| private $aggregateId; | ||
| private $name; | ||
| private $description; | ||
| private $banner; |
| return $this->aggregateId; | ||
| } | ||
|
|
||
| public static function fromNameAndDescription($name, $description) : self |
There was a problem hiding this comment.
missing type hinting public static function fromNameAndDescription(string $name, string $description) : self
|
|
||
| public function ticketId() : string | ||
| { | ||
| return $this->payload['ticked_id']; |
| public static function fromEventAndTicket(Event $event, Ticket $ticket) : self | ||
| { | ||
| return self::occur((string) $event->aggregateId(), [ | ||
| 'ticket_id' => (string)$ticket->aggregateId() |
There was a problem hiding this comment.
space missing (string)$ticket->aggregateId() and remember the comma
| final class TicketWasCreated extends AggregateChanged | ||
| { | ||
| public static function fromTicketIdEventIdAndNameAndDescription( | ||
| TicketId $ticketId, EventId $eventId, string $name, string $description |
| $this->type = $type; | ||
| $this->key = $key; | ||
| return self::occur((string) $ticketId, [ | ||
| 'event_id' => (string) $eventId, |
| public function name() : string | ||
| { | ||
| return $this->type; | ||
| return $this->payload['name']; |
…g event aggregate model
…sulating start and end dates logic
Basic arch using prooph
| */ | ||
| public function __invoke(Request $request, Response $response, callable $out = null) | ||
| { | ||
| // @todo work with post parameters |
There was a problem hiding this comment.
Are you sure about this file? I don't think we need to merge this.
There was a problem hiding this comment.
We need to improve our tests with real case scenarios. So this class will be probably fixed when we start to work on our scenarios. The merge isn't ready yet.
Substitui o Symfony pelo zend-expressive. Adicionei alguns packages como PhpSpec, Ramsei/Uuid, Beberlei/Assertion e os packages do Prooph. Também comecei a modelar o Event Aggregate, não sei se a estratégia de diretórios que tomei é a melhor, fiz isso mais pra dar um start na pull request.