/** * Increases the open_todos counter of the assignee by one * * @param TodoWasPosted $event * @throws UserNotFound */ public function onTodoWasPosted(TodoWasPosted $event) { $user = $this->userFinder->findUserOfTodo($event->todoId()->toString()); if (!$user) { throw new UserNotFound(sprintf("Data of the assigned user of the todo %s cannot be found", $event->todoId()->toString())); } $stmt = $this->connection->prepare(sprintf('UPDATE %s SET open_todos = open_todos + 1 WHERE id = :assignee_id', Table::USER)); $stmt->bindValue('assignee_id', $event->assigneeId()->toString()); $stmt->execute(); }
/** * @test * @return Todo $todo */ public function it_marks_an_open_todo_as_expired() { $todoId = TodoId::generate(); $userId = UserId::generate(); $deadline = TodoDeadline::fromString('yesterday'); $events = [TodoWasPosted::byUser($userId, 'Do something that will be forgotten', $todoId, TodoStatus::open()), DeadlineWasAddedToTodo::byUserToDate($todoId, $userId, $deadline)]; $todo = $this->reconstituteAggregateFromHistory(Todo::class, $events); $todo->markAsExpired(); $events = $this->popRecordedEvent($todo); $this->assertEquals(1, count($events)); $this->assertInstanceOf(TodoWasMarkedAsExpired::class, $events[0]); $expectedPayload = ['old_status' => 'open', 'new_status' => 'expired']; $this->assertEquals($expectedPayload, $events[0]->payload()); return $todo; }
/** * @param TodoWasPosted $event */ protected function whenTodoWasPosted(TodoWasPosted $event) { $this->todoId = $event->todoId(); $this->assigneeId = $event->assigneeId(); $this->text = $event->text(); $this->status = $event->todoStatus(); }
/** * @param TodoWasPosted $event */ public function onTodoWasPosted(TodoWasPosted $event) { $this->connection->insert(Table::TODO, ['id' => $event->todoId()->toString(), 'assignee_id' => $event->assigneeId()->toString(), 'text' => $event->text(), 'status' => $event->todoStatus()->toString()]); }