synReaderModel = $this->getMockBuilder(\Magento\Search\Model\SynonymReader::class) ->disableOriginalConstructor() ->getMock(); $this->synonymAnalyzer = $helper->getObject( \Magento\Search\Model\SynonymAnalyzer::class, [ 'synReader' => $this->synReaderModel, ] ); } /** * @test */ public function testGetSynonymsForPhrase() { $phrase = 'Elizabeth is the british queen'; $expected = [ 0 => [ 0 => "Elizabeth" ], 1 => [ 0 => "is" ], 2 => [ 0 => "the" ], 3 => [ 0 => "british", 1 => "english" ], 4 => [ 0 => "queen", 1 => "monarch" ], ]; $this->synReaderModel->expects($this->once()) ->method('loadByPhrase') ->with($phrase) ->willReturnSelf() ; $this->synReaderModel->expects($this->once()) ->method('getData') ->willReturn([ ['synonyms' => 'british,english'], ['synonyms' => 'queen,monarch'], ]) ; $actual = $this->synonymAnalyzer->getSynonymsForPhrase($phrase); $this->assertEquals($expected, $actual); } /** * @test * * Empty phrase scenario */ public function testGetSynonymsForPhraseEmptyPhrase() { $phrase = ''; $expected = []; $actual = $this->synonymAnalyzer->getSynonymsForPhrase($phrase); $this->assertEquals($expected, $actual); } }