Example #1
0
 public function testCreateItemGuidExistsAlready()
 {
     $url = 'http://test';
     $folderId = 10;
     $ex = new DoesNotExistException('yo');
     $createdFeed = new Feed();
     $createdFeed->setUrl($url);
     $createdFeed->setUrlHash($url);
     $createdFeed->setLink($url);
     $item1 = new Item();
     $item1->setGuidHash('hi');
     $item2 = new Item();
     $item2->setGuidHash('yo');
     $return = [$createdFeed, [$item1, $item2]];
     $this->feedMapper->expects($this->once())->method('findByUrlHash')->with($this->equalTo($createdFeed->getUrlHash()), $this->equalTo($this->user))->will($this->throwException($ex));
     $this->fetcher->expects($this->once())->method('fetch')->with($this->equalTo($url))->will($this->returnValue($return));
     $this->feedMapper->expects($this->once())->method('insert')->with($this->equalTo($createdFeed))->will($this->returnValue($createdFeed));
     $this->itemMapper->expects($this->at(0))->method('findByGuidHash')->with($this->equalTo($item2->getGuidHash()), $this->equalTo($item2->getFeedId()), $this->equalTo($this->user))->will($this->throwException($ex));
     $this->purifier->expects($this->at(0))->method('purify')->with($this->equalTo($return[1][1]->getBody()))->will($this->returnValue($return[1][1]->getBody()));
     $this->itemMapper->expects($this->at(1))->method('insert')->with($this->equalTo($return[1][1]));
     $this->itemMapper->expects($this->at(2))->method('findByGuidHash')->with($this->equalTo($item1->getGuidHash()), $this->equalTo($item1->getFeedId()), $this->equalTo($this->user));
     $feed = $this->feedService->create($url, $folderId, $this->user);
     $this->assertEquals($feed->getFolderId(), $folderId);
     $this->assertEquals($feed->getUrl(), $url);
     $this->assertEquals(1, $feed->getUnreadCount());
 }