Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions app/code/Magento/Search/Test/Unit/Model/SynonymAnalyzerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Search\Test\Unit\Model;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

/**
* Class SynonymAnalyzerTest
*/
class SynonymAnalyzerTest extends \PHPUnit\Framework\TestCase

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this namespace exists within a scope of 2.1. Try to use \PHPUnit_Framework_TestCase instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed and checked on 2.1 version.

{
/**
* @var \Magento\Search\Model\SynonymAnalyzer
*/
private $synonymAnalyzer;

/**
* @var \Magento\Search\Model\SynonymReader |\PHPUnit_Framework_MockObject_MockObject
*/
private $synReaderModel;

/**
* Test set up
*/
protected function setUp()
{
$helper = new ObjectManager($this);

$this->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);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add an extra empty line after the class closing bracket.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done