Skip to content

Commit 34462d0

Browse files
committed
MC-31304: [ElasticSearch] Exception on catalog search result page
1 parent 01450cb commit 34462d0

File tree

1 file changed

+7
-71
lines changed

1 file changed

+7
-71
lines changed

app/code/Magento/Elasticsearch/Test/Unit/Model/ConfigTest.php

Lines changed: 7 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@
77

88
namespace Magento\Elasticsearch\Test\Unit\Model;
99

10-
use Magento\AdvancedSearch\Model\Client\ClientResolver;
1110
use Magento\Elasticsearch\Model\Config;
1211
use Magento\Framework\App\Config\ScopeConfigInterface;
13-
use Magento\Store\Model\ScopeInterface;
1412
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1513
use PHPUnit\Framework\MockObject\MockObject;
1614
use PHPUnit\Framework\TestCase;
1715

18-
/**
19-
* Elasticsearch config model tests.
20-
*/
2116
class ConfigTest extends TestCase
2217
{
2318
/**
@@ -28,17 +23,7 @@ class ConfigTest extends TestCase
2823
/**
2924
* @var ScopeConfigInterface|MockObject
3025
*/
31-
protected $scopeConfigMock;
32-
33-
/**
34-
* @var ClientResolver|MockObject
35-
*/
36-
private $clientResolverMock;
37-
38-
/**
39-
* @var ObjectManagerHelper
40-
*/
41-
private $objectManager;
26+
protected $scopeConfig;
4227

4328
/**
4429
* Setup
@@ -47,17 +32,15 @@ class ConfigTest extends TestCase
4732
*/
4833
protected function setUp(): void
4934
{
50-
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
35+
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)
5136
->disableOriginalConstructor()
5237
->getMockForAbstractClass();
53-
$this->clientResolverMock = $this->createMock(ClientResolver::class);
5438

55-
$this->objectManager = new ObjectManagerHelper($this);
56-
$this->model = $this->objectManager->getObject(
39+
$objectManager = new ObjectManagerHelper($this);
40+
$this->model = $objectManager->getObject(
5741
Config::class,
5842
[
59-
'scopeConfig' => $this->scopeConfigMock,
60-
'clientResolver' => $this->clientResolverMock,
43+
'scopeConfig' => $this->scopeConfig
6144
]
6245
);
6346
}
@@ -67,7 +50,7 @@ protected function setUp(): void
6750
*/
6851
public function testPrepareClientOptions()
6952
{
70-
$this->scopeConfigMock->expects($this->any())
53+
$this->scopeConfig->expects($this->any())
7154
->method('getValue')
7255
->willReturn('');
7356
$options = [
@@ -87,7 +70,7 @@ public function testPrepareClientOptions()
8770
*/
8871
public function testGetIndexPrefix()
8972
{
90-
$this->scopeConfigMock->expects($this->any())
73+
$this->scopeConfig->expects($this->any())
9174
->method('getValue')
9275
->willReturn('indexPrefix');
9376
$this->assertEquals('indexPrefix', $this->model->getIndexPrefix());
@@ -108,51 +91,4 @@ public function testIsElasticsearchEnabled()
10891
{
10992
$this->assertFalse($this->model->isElasticsearchEnabled());
11093
}
111-
112-
/**
113-
* Test retrieve search engine configuration information.
114-
*
115-
* @return void
116-
*/
117-
public function testGetElasticsearchConfigData(): void
118-
{
119-
$fieldName = 'server_hostname';
120-
121-
$this->clientResolverMock->expects($this->once())
122-
->method('getCurrentEngine')
123-
->willReturn(Config::ENGINE_NAME);
124-
125-
$this->scopeConfigMock->expects($this->once())
126-
->method('getValue')
127-
->with('catalog/search/' . Config::ENGINE_NAME . '_' . $fieldName, ScopeInterface::SCOPE_STORE, 1);
128-
129-
$this->model->getElasticsearchConfigData($fieldName, 1);
130-
}
131-
132-
/**
133-
* Test retrieve search engine configuration information with predefined prefix.
134-
*
135-
* @return void
136-
*/
137-
public function testGetElasticsearchConfigDataWithPredefinedPrefix(): void
138-
{
139-
$fieldName = 'server_hostname';
140-
$model = $this->objectManager->getObject(
141-
Config::class,
142-
[
143-
'scopeConfig' => $this->scopeConfigMock,
144-
'clientResolver' => $this->clientResolverMock,
145-
'prefix' => Config::ENGINE_NAME,
146-
]
147-
);
148-
149-
$this->clientResolverMock->expects($this->never())
150-
->method('getCurrentEngine');
151-
152-
$this->scopeConfigMock->expects($this->once())
153-
->method('getValue')
154-
->with('catalog/search/' . Config::ENGINE_NAME . '_' . $fieldName, ScopeInterface::SCOPE_STORE, 1);
155-
156-
$model->getElasticsearchConfigData($fieldName, 1);
157-
}
15894
}

0 commit comments

Comments
 (0)