/**
  * @test
  */
 public function canBuildJsonFromSynonymCollection()
 {
     $synonymCollection = new SynonymCollection();
     $synonym = new Synonym();
     $synonym->setMainWord("lucky");
     $synonym->addWordsWithSameMeaning("happy");
     $synonymCollection->add($synonym);
     $this->assertEquals(1, $synonymCollection->getCount());
     $expectedJson = '{"lucky":["happy"]}';
     $json = $this->dataMapper->toJson($synonymCollection);
     $this->assertEquals($expectedJson, $json);
 }
 /**
  * Convert from json returned by solr restAPI from searching by synonym word
  *
  * @param string $json
  * @param string $mainWord
  * @param string $tag
  * @return SynonymCollection
  */
 public function fromJsonToMainWordCollection($json, $mainWord = '', $tag = '')
 {
     $synonymCollection = new SynonymCollection();
     $object = json_decode($json);
     if (!is_object($object) || !isset($object->{$mainWord}) || count($object->{$mainWord}) == 0) {
         return $synonymCollection;
     }
     $synonym = new Synonym();
     $synonym->setMainWord($mainWord);
     $synonym->setTag($tag);
     foreach ($object->{$mainWord} as $wordWithSameMeaning) {
         $synonym->addWordsWithSameMeaning($wordWithSameMeaning);
     }
     $synonymCollection->add($synonym);
     return $synonymCollection;
 }
 /**
  * @test
  */
 public function canDeleteAll()
 {
     $synonymsCount = 5;
     $synonymCollection = new \SolrRestApiClient\Api\Client\Domain\Synonym\SynonymCollection();
     for ($i = 0; $i < $synonymsCount; $i++) {
         $synonym = new \SolrRestApiClient\Api\Client\Domain\Synonym\Synonym();
         $synonym->setMainWord('foo');
         $synonym->addWordsWithSameMeaning('bar');
         $synonym->addWordsWithSameMeaning('bla');
         $synonym->addWordsWithSameMeaning('bluqqqqqqqqqqq');
         $synonymCollection->add($synonym);
     }
     $this->synonymRepository = $this->getMock('SolrRestApiClient\\Api\\Client\\Domain\\Synonym\\SynonymRepository', array('executeDeleteRequest', 'executeGetRequest', 'executePostRequest', 'getAll', 'getTag'));
     $this->synonymRepository->injectDataMapper($this->dataMapper);
     $this->synonymRepository->expects($this->once())->method('getTag');
     $this->synonymRepository->expects($this->once())->method('getAll')->will($this->returnValue($synonymCollection));
     $responseMock = $this->getMock('Guzzle\\Http\\Message\\Response', array('getBody', 'getStatusCode'), array(), '', false);
     $responseMock->expects($this->exactly($synonymsCount))->method('getStatusCode')->will($this->returnValue(200));
     $endpoint = 'solr/schema/analysis/synonyms//foo';
     $this->synonymRepository->expects($this->exactly($synonymsCount))->method('executeDeleteRequest')->with($endpoint)->will($this->returnValue($responseMock));
     $this->assertTrue($this->synonymRepository->deleteAll());
 }