public function updateTaskDescription(ChangeTaskDescription $request, $taskListId, $taskId)
 {
     // Update task description using command and service to handle this.
     // Normally this would be on a command bus and split across a couple of different serivces etc.
     // A writing service and a reading service
     $command = new ChangeTaskDescriptionCommand(TaskListId::fromString($taskListId), TaskId::fromString($taskId), $request->get('description'));
     $this->taskListService->handleChangeTaskDescription($command);
     return redirect()->route('lists.show', (string) $taskListId);
 }
 /** @test */
 function it_can_load_pending_changes_for_an_aggregate()
 {
     $taskListId = TaskListId::generate();
     $taskId = TaskId::generate();
     $domainEvents = new DomainEvents();
     $domainEvents->push(new TaskWasAdded($taskListId, $taskId, 'My new task'));
     $taskList = TaskList::reconstituteFrom($taskListId, $domainEvents);
     $taskList->changeTaskDescription($taskId, 'Foo Task');
     $this->SUT->savePendingChanges($taskListId, $taskList->getPendingChanges());
     $pendingChanges = $this->SUT->loadPendingChanges($taskListId);
     $this->assertCount(1, $pendingChanges);
     $this->assertInstanceOf(TaskDescriptionWasChanged::class, $pendingChanges->first());
 }
 /**
  * {@inheritDoc}
  */
 public static function deserialize($aggregateId, array $data)
 {
     $taskListId = TaskListId::fromString($aggregateId);
     $taskId = TaskId::fromString($data['taskId']);
     return new static($taskListId, $taskId, $data['taskDescription'], $data['taskPriority']);
 }
 /** @test */
 function it_overrides_existing_pending_changes()
 {
     $taskListId = TaskListId::generate();
     $taskId = TaskId::generate();
     $domainEvents = new DomainEvents();
     $domainEvents->push(new TaskWasAdded($taskListId, $taskId, 'Learn more DDD!'));
     $pendingChanges = new DomainEvents();
     $existingChange = new TaskDescriptionWasChanged($taskListId, $taskId, 'Learn more DDD!', 'Implement Event Sourcing');
     $pendingChanges->push($existingChange);
     $taskList = TaskList::reconstituteFrom($taskListId, $domainEvents, $pendingChanges);
     $taskList->changeTaskDescription($taskId, 'Foo Bar Baz');
     $pendingChanges = $taskList->getPendingChanges();
     $this->assertCount(1, $pendingChanges);
     $this->assertEquals('Foo Bar Baz', $pendingChanges->first()->getNewDescription());
 }