Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SynonymsTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class SynonymsTest extends \PHPUnit\Framework\TestCase
11 {
15  private $synonymAnalyzer;
16 
20  private $synonymPreprocessor;
21 
22  protected function setUp()
23  {
24  $objectManager = new ObjectManager($this);
25 
26  $this->synonymAnalyzer = $this->getMockBuilder(\Magento\Search\Model\SynonymAnalyzer::class)
27  ->setMethods(['getSynonymsForPhrase'])
28  ->disableOriginalConstructor()
29  ->getMock();
30 
31  $this->synonymPreprocessor = $objectManager->getObject(
32  \Magento\Search\Adapter\Query\Preprocessor\Synonyms::class,
33  [
34  'synonymsAnalyzer' => $this->synonymAnalyzer
35  ]
36  );
37  }
38 
44  public static function loadProcessDataProvider()
45  {
46  return [
47  'oneWord' => [
48  'query' => 'big',
49  'result' => [['big', 'huge']],
50  'newQuery' => 'big huge'
51  ],
52  'twoWords' => [
53  'query' => 'big universe',
54  'result' => [['big', 'huge'], ['universe', 'cosmos']],
55  'newQuery' => 'big huge universe cosmos'
56  ],
57  'noSynonyms' => [
58  'query' => 'no synonyms',
59  'result' => [['no'], ['synonyms']],
60  'newQuery' => 'no synonyms'
61  ]
62  ];
63  }
64 
70  public function testProcess($query, $result, $newQuery)
71  {
72  $this->synonymAnalyzer->expects($this->once())
73  ->method('getSynonymsForPhrase')
74  ->with($this->equalTo($query))
75  ->will($this->returnValue($result));
76 
77  $result = $this->synonymPreprocessor->process($query);
78  $this->assertEquals($result, $newQuery);
79  }
80 }
$objectManager
Definition: bootstrap.php:17