/**
  * @param int|null $limit
  * @return ShortenedUrl[]
  */
 public function getNewest($limit = null)
 {
     $shortenedUrls = [];
     $shortenedUrlSuffixes = $this->shortenedUrlSuffixRepo->findNewest($limit);
     $suffixIds = $this->getSuffixIds($shortenedUrlSuffixes);
     $totalExecutionsBySuffixId = $this->urlCallRepo->getCallCountsBySuffixId($suffixIds);
     $totalExecutionsByOriginalUrlId = $this->getTotalExecutionsByOriginalUrlId($suffixIds);
     foreach ($shortenedUrlSuffixes as $suffix) {
         $totalExecutions = $this->getExecutionCount($suffix, $totalExecutionsBySuffixId);
         $totalOriginalUrlExecutions = $this->getOriginalUrlExecutionCount($suffix, $totalExecutionsByOriginalUrlId);
         $shortenedUrls[] = $this->shortenedUrlFactory->create($suffix, $totalExecutions, $totalOriginalUrlExecutions);
     }
     return $shortenedUrls;
 }
 public function test_it_creates_and_returns_new_shortened_url_entity()
 {
     $suffixString = "shortStr";
     $encodedLink = "encoded-link";
     $someDate = new \DateTime();
     $shortenedUrlSuffix = m::mock('AppBundle\\Entity\\ShortenedUrlSuffix', ['getSuffixString' => $suffixString, 'getOriginalUrlEncodedLink' => $encodedLink, 'getDateCreated' => $someDate]);
     $totalExecutions = 2;
     $totalRedirectsToSameContent = 5;
     $shortenedLink = "http://shortStr";
     $originalLink = "http://original-decoded-link";
     $this->localUrlAssembler->shouldReceive('assemble')->with($suffixString)->andReturn($shortenedLink);
     $this->urlEncoder->shouldReceive('decode')->with($encodedLink)->andReturn($originalLink);
     $result = $this->factory->create($shortenedUrlSuffix, $totalExecutions, $totalRedirectsToSameContent);
     $this->assertInstanceOf('AppBundle\\Model\\ShortenedUrl', $result);
     $this->assertEquals($shortenedLink, $result->getLink());
     $this->assertEquals($originalLink, $result->getOriginalLink());
     $this->assertEquals($someDate, $result->getDateCreated());
     $this->assertEquals($totalExecutions, $result->getTimesExecuted());
     $this->assertEquals($totalRedirectsToSameContent, $result->getTimesOriginalUrlExecuted());
 }