/** @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());
 }
 /** @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());
 }