/**
  * Tests the findOneByProviderAndLongUrl method
  */
 public function testFindOneByProviderAndLongUrl()
 {
     $provider = $this->getMock('Mremi\\UrlShortener\\Provider\\UrlShortenerProviderInterface');
     $provider->expects($this->once())->method('getName')->will($this->returnValue('google'));
     $provider->expects($this->once())->method('shorten');
     $this->chainProvider->expects($this->once())->method('getProvider')->with($this->equalTo('google'))->will($this->returnValue($provider));
     $link = $this->manager->findOneByProviderAndLongUrl('google', 'http://www.google.com/');
     $this->assertInstanceOf('Mremi\\UrlShortener\\Model\\Link', $link);
     $this->assertEquals('http://www.google.com/', $link->getLongUrl());
 }
 public function getShortUrl($type = 'bitly', $url = 'http://www.google.com')
 {
     $shortLink = null;
     /** @var ShortLink $link */
     if ($shortLink = $this->tryGetShortLinkDB($type, $url)) {
         return $shortLink;
     } else {
         /** @var LinkInterface $shortened */
         $shortened = $this->linkManager->findOneByProviderAndLongUrl($type, $url);
         $shortUrl = $shortened->getShortUrl();
         $shortLink = new ShortLink();
         $shortLink->setType($type);
         $shortLink->setLongUrl($url);
         $shortLink->setShortUrl($shortUrl);
         $this->entityManager->persist($shortLink);
         $this->entityManager->flush();
     }
     return $shortLink;
 }