Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SynonymAnalyzerTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 
15 class SynonymAnalyzerTest extends \PHPUnit\Framework\TestCase
16 {
20  private $synonymAnalyzer;
21 
25  private $synReaderModel;
26 
30  protected function setUp()
31  {
32  $helper = new ObjectManager($this);
33 
34  $this->synReaderModel = $this->getMockBuilder(\Magento\Search\Model\SynonymReader::class)
35  ->disableOriginalConstructor()
36  ->getMock();
37 
38  $this->synonymAnalyzer = $helper->getObject(
39  \Magento\Search\Model\SynonymAnalyzer::class,
40  [
41  'synReader' => $this->synReaderModel,
42  ]
43  );
44  }
45 
49  public function testGetSynonymsForPhrase()
50  {
51  $phrase = 'Elizabeth is the british queen';
52  $expected = [
53  0 => [ 0 => "Elizabeth" ],
54  1 => [ 0 => "is" ],
55  2 => [ 0 => "the" ],
56  3 => [ 0 => "british", 1 => "english" ],
57  4 => [ 0 => "queen", 1 => "monarch" ],
58  ];
59  $this->synReaderModel->expects($this->once())
60  ->method('loadByPhrase')
61  ->with($phrase)
62  ->willReturnSelf()
63  ;
64  $this->synReaderModel->expects($this->once())
65  ->method('getData')
66  ->willReturn([
67  ['synonyms' => 'british,english'],
68  ['synonyms' => 'queen,monarch'],
69  ])
70  ;
71 
72  $actual = $this->synonymAnalyzer->getSynonymsForPhrase($phrase);
73  $this->assertEquals($expected, $actual);
74  }
75 
82  {
83  $phrase = '';
84  $expected = [];
85  $actual = $this->synonymAnalyzer->getSynonymsForPhrase($phrase);
86  $this->assertEquals($expected, $actual);
87  }
88 }
$helper
Definition: iframe.phtml:13