From d7bf38c8e1582c4677d9e6235f4d37655cd19295 Mon Sep 17 00:00:00 2001 From: Ihor Furseyev Date: Tue, 28 Aug 2018 14:28:04 +0300 Subject: [PATCH] [Search] Unit test for SynonymAnalyzer model --- .../Test/Unit/Model/SynonymAnalyzerTest.php | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 app/code/Magento/Search/Test/Unit/Model/SynonymAnalyzerTest.php diff --git a/app/code/Magento/Search/Test/Unit/Model/SynonymAnalyzerTest.php b/app/code/Magento/Search/Test/Unit/Model/SynonymAnalyzerTest.php new file mode 100644 index 0000000000000..45dcfbd2d0c32 --- /dev/null +++ b/app/code/Magento/Search/Test/Unit/Model/SynonymAnalyzerTest.php @@ -0,0 +1,86 @@ +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); + } +}