Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 9e44d9a

Browse files
author
Stanislav Idolov
authored
🔃 [EngCom] Public Pull Requests - 2.1-develop
Accepted Public Pull Requests: - magento/magento2#17839: [Backport] [Search] Unit test for SynonymAnalyzer model. 2.1 back port. (by @furseyev)
2 parents 52377b5 + dc02024 commit 9e44d9a

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Search\Test\Unit\Model;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
10+
/**
11+
* Class SynonymAnalyzerTest
12+
*/
13+
class SynonymAnalyzerTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var \Magento\Search\Model\SynonymAnalyzer
17+
*/
18+
private $synonymAnalyzer;
19+
20+
/**
21+
* @var \Magento\Search\Model\SynonymReader |\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $synReaderModel;
24+
25+
/**
26+
* Test set up
27+
*/
28+
protected function setUp()
29+
{
30+
$helper = new ObjectManager($this);
31+
32+
$this->synReaderModel = $this->getMockBuilder(\Magento\Search\Model\SynonymReader::class)
33+
->disableOriginalConstructor()
34+
->getMock();
35+
36+
$this->synonymAnalyzer = $helper->getObject(
37+
\Magento\Search\Model\SynonymAnalyzer::class,
38+
[
39+
'synReader' => $this->synReaderModel,
40+
]
41+
);
42+
}
43+
44+
/**
45+
* @test
46+
*/
47+
public function testGetSynonymsForPhrase()
48+
{
49+
$phrase = 'Elizabeth is the british queen';
50+
$expected = [
51+
0 => [ 0 => "Elizabeth" ],
52+
1 => [ 0 => "is" ],
53+
2 => [ 0 => "the" ],
54+
3 => [ 0 => "british", 1 => "english" ],
55+
4 => [ 0 => "queen", 1 => "monarch" ],
56+
];
57+
$this->synReaderModel->expects($this->once())
58+
->method('loadByPhrase')
59+
->with($phrase)
60+
->willReturnSelf()
61+
;
62+
$this->synReaderModel->expects($this->once())
63+
->method('getData')
64+
->willReturn([
65+
['synonyms' => 'british,english'],
66+
['synonyms' => 'queen,monarch'],
67+
])
68+
;
69+
70+
$actual = $this->synonymAnalyzer->getSynonymsForPhrase($phrase);
71+
$this->assertEquals($expected, $actual);
72+
}
73+
74+
/**
75+
* @test
76+
*
77+
* Empty phrase scenario
78+
*/
79+
public function testGetSynonymsForPhraseEmptyPhrase()
80+
{
81+
$phrase = '';
82+
$expected = [];
83+
$actual = $this->synonymAnalyzer->getSynonymsForPhrase($phrase);
84+
$this->assertEquals($expected, $actual);
85+
}
86+
}

0 commit comments

Comments
 (0)