public function confirm($id)
 {
     // Confirm changes using a command and a handler, again this would normally be done via mapping
     // and maybe split across some files.
     $command = new ConfirmPendingChangesCommand(TaskListId::fromString($id));
     $this->taskListService->handleConfirmPendingChanges($command);
     return redirect()->route('lists.show', [$id, 'success' => true]);
 }
 /** @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)
 {
     return new static(TaskListId::fromString($aggregateId));
 }
 /**
  * {@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());
 }