/**
  * @test
  */
 public function canBuildJsonFromStopWordCollection()
 {
     $stopWordCollection = new StopWordCollection();
     $stopWord = new StopWord();
     $stopWord->setWord("test");
     $stopWordCollection->add($stopWord);
     $this->assertEquals(1, $stopWordCollection->getCount());
     $expectedJson = '["test"]';
     $json = $this->dataMapper->toJson($stopWordCollection);
     $this->assertEquals($expectedJson, $json);
 }
 /**
  * @param string $json
  * @return StopWordCollection
  */
 public function fromJson($json)
 {
     $stopWordCollection = new StopWordCollection();
     $object = json_decode($json);
     if (!is_object($object) || !isset($object->wordSet->managedList)) {
         return $stopWordCollection;
     }
     $mapping = $object->wordSet->managedList;
     foreach ($mapping as $word) {
         $stopWord = new StopWord();
         $stopWord->setWord($word);
         $stopWordCollection->add($stopWord);
     }
     return $stopWordCollection;
 }
 /**
  * Test to see if a specific word exists
  *
  * @param string $word
  * @param string $forceResourceTag
  * @return StopWordCollection
  */
 public function getByWord($word = '', $forceResourceTag = null)
 {
     $stopwordCollection = new StopWordCollection();
     try {
         $resourceTag = $this->getTag($forceResourceTag);
         $endpoint = $this->getEndpoint(array($resourceTag));
         if (trim($word) != '') {
             $endpoint = $endpoint . '/' . $word;
         }
         $response = $this->executeGetRequest($endpoint);
         if ($response->getStatusCode() == 200) {
             $stopWord = new StopWord();
             $stopWord->setWord($word);
             $stopWord->setTag($resourceTag);
             $stopwordCollection->add($stopWord);
         }
     } catch (\Guzzle\Http\Exception\BadResponseException $e) {
         if ($e->getResponse()->getStatusCode() === 404) {
             return $stopwordCollection;
         }
     }
     return $stopwordCollection;
 }
 /**
  * @test
  */
 public function canGetByWord()
 {
     $stopwordCollection = new StopWordCollection();
     $stopword = new StopWord();
     $stopword->setWord('foo');
     $stopwordCollection->add($stopword);
     $expectedJson = '["foo"]';
     $responseMock = $this->getMock('Guzzle\\Http\\Message\\Response', array('getBody', 'getStatusCode'), array(), '', false);
     $responseMock->expects($this->exactly(2))->method('getStatusCode')->will($this->returnValue(200));
     $this->stopwordRepository->expects($this->once())->method('executePostRequest')->with('solr/schema/analysis/stopwords/it', $expectedJson)->will($this->returnValue($responseMock));
     $response = $this->stopwordRepository->addAll($stopwordCollection, 'it');
     $this->assertTrue($response);
     $this->stopwordRepository->expects($this->once())->method('executeGetRequest')->with('solr/schema/analysis/stopwords/default/foo')->will($this->returnValue($responseMock));
     $foundedWord = $this->stopwordRepository->getByWord('foo');
     $this->assertEquals('foo', $foundedWord->getByIndex(0)->getWord(), "Word not found");
 }