public function testCanSortCollectionByCallable()
 {
     $collection = new EventEnvelopeCollection();
     $first_event = $this->getTestEvent('Unit-Test-1');
     $second_event = $this->getTestEvent('Unit-Test-2');
     $first_envelope = new EventEnvelope($first_event, []);
     $second_envelope = new EventEnvelope($second_event, []);
     $collection[] = $first_envelope;
     $collection[] = $second_envelope;
     /**
      * Sort in reverse order
      */
     /** @var EventEnvelopeCollection $collection */
     $collection->sort(function (ServesEventStreamData $a, ServesEventStreamData $b) {
         if ($a->getOccurredOnMicrotime() < $b->getOccurredOnMicrotime()) {
             return 1;
         } elseif ($a->getOccurredOnMicrotime() > $b->getOccurredOnMicrotime()) {
             return -1;
         } else {
             return 0;
         }
     });
     $this->assertSame($second_envelope, $collection[0]);
     $this->assertSame($first_envelope, $collection[1]);
 }
 /**
  * @return CollectsEventEnvelopes
  */
 public function getChanges()
 {
     $changes = new EventEnvelopeCollection();
     foreach ($this->aggregateRoots as $aggregateRoot) {
         if ($aggregateRoot->hasChanges()) {
             $changes->append($aggregateRoot->getChanges());
         }
     }
     $changes->sort($this->getChangesSortFunction());
     return $changes;
 }