Skip to content

Commit 9478ec5

Browse files
committed
MC-18948: Switch default search engine from MySQL to ElasticSearch
- skip tests
1 parent 5aff7a3 commit 9478ec5

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

app/code/Magento/CatalogSearch/Model/Advanced/ProductCollectionPrepareStrategyProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\CatalogSearch\Model\Advanced;
77

88
use Magento\Framework\Search\EngineResolverInterface;
9+
use Magento\Framework\Exception\RuntimeException;
910

1011
/**
1112
* Strategy provider for preparing product collection.
@@ -38,15 +39,15 @@ public function __construct(
3839
* Get strategy provider for product collection prepare process.
3940
*
4041
* @return ProductCollectionPrepareStrategyInterface
41-
* @throws \Exception
42+
* @throws RuntimeException
4243
*/
4344
public function getStrategy(): ProductCollectionPrepareStrategyInterface
4445
{
4546
if (!isset($this->strategies[$this->engineResolver->getCurrentSearchEngine()])) {
4647
if ($this->strategies['default']) {
4748
return $this->strategies['default'];
4849
} else {
49-
throw new \Exception('Default product collection strategy not found');
50+
throw new RuntimeException(__('Default product collection strategy not found'));
5051
}
5152
}
5253
return $this->strategies[$this->engineResolver->getCurrentSearchEngine()];

app/code/Magento/Search/Model/EngineResolver.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Framework\App\Config\ScopeConfigInterface;
99
use Magento\Framework\Search\EngineResolverInterface;
1010
use Psr\Log\LoggerInterface;
11+
use Magento\Framework\Exception\RuntimeException;
1112

1213
/**
1314
* Search engine resolver model.
@@ -91,7 +92,7 @@ public function __construct(
9192
* It returns string identifier of Search Engine that is currently chosen in configuration
9293
*
9394
* @return string
94-
* @throws \Exception
95+
* @throws RuntimeException
9596
* @since 100.1.0
9697
*/
9798
public function getCurrentSearchEngine()
@@ -109,13 +110,13 @@ public function getCurrentSearchEngine()
109110
$defaultEngine = $this->scopeConfig->getValue(
110111
$this->path
111112
);
112-
if ($defaultEngine) {
113+
if (in_array($defaultEngine, $this->engines)) {
113114
$this->logger->error(
114115
$engine . ' search engine doesn\'t exist. Falling back to ' . $defaultEngine
115116
);
116117
return $defaultEngine;
117118
} else {
118-
throw new \Exception($engine . ' search engine doesn\'t exist');
119+
throw new RuntimeException(__('"%1" search engine doesn\'t exist', $engine));
119120
}
120121
}
121122
}

app/code/Magento/Search/Test/Unit/Model/EngineResolverTest.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function setUp()
6262
$this->path = 'catalog/search/engine';
6363
$this->scopeType = 'default';
6464
$this->scopeCode = null;
65-
$this->engines = [EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE, 'anotherengine'];
65+
$this->engines = ['defaultentengine', 'anotherengine'];
6666

6767
$this->model = new EngineResolver(
6868
$this->scopeConfig,
@@ -91,21 +91,40 @@ public function testGetCurrentSearchEngine()
9191
/**
9292
* Test getCurrentSearchEngine
9393
*/
94-
public function testGetCurrentSearchEngineWithoutEngine()
94+
public function testGetCurrentSearchEngineDefaultEngine()
9595
{
9696
$engine = 'nonexistentengine';
97+
$defaultEngine = 'defaultentengine';
9798

98-
$this->scopeConfig->expects($this->any())
99+
$this->scopeConfig->expects($this->at(0))
99100
->method('getValue')
100101
->willReturn($engine);
101102

103+
$this->scopeConfig->expects($this->at(1))
104+
->method('getValue')
105+
->willReturn($defaultEngine);
106+
102107
$this->loggerMock->expects($this->any())
103108
->method('error')
104109
->with(
105-
$engine . ' search engine doesn\'t exists. Falling back to '
106-
. EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE
110+
"{$engine} search engine doesn't exist. Falling back to {$defaultEngine}"
107111
);
108112

109-
$this->assertEquals(EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE, $this->model->getCurrentSearchEngine());
113+
$this->assertEquals($defaultEngine, $this->model->getCurrentSearchEngine());
114+
}
115+
116+
/**
117+
* Test getCurrentSearchEngine
118+
* @expectedException \Exception
119+
*/
120+
public function testGetCurrentSearchEngineWithoutEngine()
121+
{
122+
$engine = null;
123+
124+
$this->scopeConfig->expects($this->any())
125+
->method('getValue')
126+
->willReturn($engine);
127+
128+
$this->model->getCurrentSearchEngine();
110129
}
111130
}

0 commit comments

Comments
 (0)