/**
  * @param string $url
  * @return string
  */
 public function create($url)
 {
     $newUrlSuffix = $this->getShortened($url);
     $originalUrlEntity = $this->getOriginalUrlEntity($this->urlEncoder->encode($url));
     $shortenedUrlSuffixEntity = $this->shortenedUrlSuffixFactory->create($originalUrlEntity, $newUrlSuffix);
     $this->entityManager->persist($shortenedUrlSuffixEntity);
     $this->entityManager->flush();
     $shortenedUrl = $this->getShortenedUrlsService->getBySuffix($shortenedUrlSuffixEntity);
     return $shortenedUrl;
 }
 public function test_it_returns_specified_number_of_recently_shortened_urls()
 {
     $suffixes = [$this->getMockShortenedUrlSuffix(1, 11)];
     $this->shortenedUrlSuffixRepo->shouldReceive('findNewest')->with(1)->andReturn($suffixes);
     $this->urlCallRepo->shouldReceive('getCallCountsBySuffixId')->andReturn([1 => 0]);
     $this->shortenedUrlSuffixRepo->shouldReceive('getOriginalUrlIds')->andReturn([11]);
     $this->urlCallRepo->shouldReceive('getCallCountsByOriginalUrlId')->andReturn([11 => 5]);
     $shortenedUrl = $this->getMockShortenedUrl();
     $this->shortenedUrlFactory->shouldReceive('create')->andReturn($shortenedUrl);
     $result = $this->service->getNewest(1);
     $this->assertEquals([$shortenedUrl], $result);
 }