/**
  * Get logged events.
  *
  * @return IEvent[]
  */
 public function getEvents()
 {
     $events = [];
     try {
         $files = $this->reader->readDir($this->directory);
         foreach ($files as $file) {
             $filePath = $this->directory . '/' . $file;
             $contents = $this->reader->read($filePath);
             $parts = explode(PHP_EOL, $contents);
             $line1 = explode(' ', $parts[0]);
             $method = $line1[0];
             $endpoint = $line1[1];
             $reference = $parts[1];
             $request = $parts[2];
             $event = $this->eventFactory->create($request, $endpoint, $method, $reference);
             if (5 === count($parts)) {
                 $event->setLatency((double) $parts[3]);
                 $event->setResponse($parts[4]);
             }
             $events[] = $event;
         }
     } catch (Exception $e) {
         if (null !== $this->logger) {
             $this->logger->error($e);
         }
     }
     return $events;
 }
    function it_returns_all_of_its_events(IReader $reader, IEventFactory $eventFactory, IEvent $event)
    {
        $reader->readDir('../../../tests/fixtures/communication-logger')->shouldBeCalled()->willReturn(['example.com.876983e7-e64c-4757-ab8b-7aae4a0f6ae0.event']);
        $reader->read('../../../tests/fixtures/communication-logger/example.com.876983e7-e64c-4757-ab8b-7aae4a0f6ae0.event')->shouldBeCalled()->willreturn('POST http://example.com
ref
request
0.56
response');
        $eventFactory->create('request', 'http://example.com', 'POST', 'ref')->shouldBeCalled()->willReturn($event);
        $event->setLatency(0.5600000000000001)->shouldBeCalled();
        $event->setResponse('response')->shouldBeCalled();
        $this->getEvents()->shouldBeArray();
    }