public function testShouldReturnExists() { $us = new UrlShortcut(); $us->setSlug('zloi'); $us->setUrl('http://ya.ru'); $this->repository->expects($this->once())->method('findOneByUrl')->with($this->equalTo('http://ya.ru'))->will($this->returnValue($us)); $shortener = $this->shortener; $actual = $shortener->isExists('http://ya.ru'); $this->assertEquals(true, $actual); }
/** * @param UrlShortcut $urlShortcut * @return string */ public function registerShortcut(UrlShortcut $urlShortcut) { $url = strtolower(trim($urlShortcut->getUrl())); if (!$this->isExists($url)) { $urlShortcut->setSlug('dummy'); $urlShortcut->setCreatedAt(new \DateTime('now', new \DateTimeZone('UTC'))); $urlShortcut->setClicks(0); $urlShortcut = $this->save($urlShortcut, false); $id = $urlShortcut->getId(); $urlShortcut->setSlug($this->id2slug($id)); $urlShortcut = $this->save($urlShortcut); } else { $urlShortcut = $this->getByUrl($url); } return $urlShortcut->getSlug(); }