function it_can_be_attached_to_a_category() { $stream = new Stream(); $stream->addEvent(new TransactionWasCreated(Uuid::uuid4(), '20150730', 'This is a shorter description that is really long', '1234567890', '0987654321', "GT", "30,00", "This is a description")); $stream->addEvent(new TransactionWasAttachedToCategory(Uuid::uuid4())); $stream->addEvent(new TransactionWasAttachedToCategory(Uuid::uuid4())); $this->replay($stream)->shouldHaveType(Transaction::class); $this->getCategories()->shouldHaveCount(2); }
public function replay(Stream $stream) { foreach ($stream->replay() as $event) { switch (get_class($event)) { case CategoryWasCreated::class: $this->id = Uuid::fromString($event->getId()); $this->title = $event->getTitle(); $this->type = $event->getType(); } } return $this; }
public function replay(Stream $stream) { /** @var Event $event */ foreach ($stream->replay() as $event) { switch (get_class($event)) { case TransactionWasCreated::class: $this->id = Id::fromString($event->getId()); $this->date = Date::fromString($event->getDate()); $this->from = Account::fromNumber($event->getFrom()); $this->to = Account::withName($event->getTo(), $event->getName()); $this->code = Code::fromString($event->getCode()); $this->amount = Amount::fromString($event->getAmount()); $this->description = Description::fromString($event->getDescription()); break; case TransactionWasAttachedToCategory::class: $this->categories[] = $event->getCategoryId(); break; } } return $this; }
function it_can_be_created_from_stream() { $stream = new Stream(); $stream->addEvent(new CategoryWasCreated(Uuid::uuid4(), "Groceries", "Food")); $this->replay($stream)->shouldHaveType(Category::class); }