Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EngineResolverTest.php
Go to the documentation of this file.
1 <?php
7 
10 use Psr\Log\LoggerInterface;
11 
12 class EngineResolverTest extends \PHPUnit\Framework\TestCase
13 {
17  private $model;
18 
22  private $scopeConfig;
23 
27  private $path;
28 
32  private $scopeType;
33 
37  private $scopeCode;
38 
42  private $engines = [];
43 
47  private $loggerMock;
48 
54  protected function setUp()
55  {
56  $this->scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
57  ->disableOriginalConstructor()
58  ->getMock();
59  $this->loggerMock = $this->getMockBuilder(LoggerInterface::class)
60  ->getMockForAbstractClass();
61 
62  $this->path = 'catalog/search/engine';
63  $this->scopeType = 'default';
64  $this->scopeCode = null;
65  $this->engines = [EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE, 'anotherengine'];
66 
67  $this->model = new EngineResolver(
68  $this->scopeConfig,
69  $this->engines,
70  $this->loggerMock,
71  $this->path,
72  $this->scopeType,
73  $this->scopeCode
74  );
75  }
76 
80  public function testGetCurrentSearchEngine()
81  {
82  $engine = 'anotherengine';
83 
84  $this->scopeConfig->expects($this->any())
85  ->method('getValue')
86  ->willReturn($engine);
87 
88  $this->assertEquals($engine, $this->model->getCurrentSearchEngine());
89  }
90 
95  {
96  $engine = 'nonexistentengine';
97 
98  $this->scopeConfig->expects($this->any())
99  ->method('getValue')
100  ->willReturn($engine);
101 
102  $this->loggerMock->expects($this->any())
103  ->method('error')
104  ->with(
105  $engine . ' search engine doesn\'t exists. Falling back to '
107  );
108 
109  $this->assertEquals(EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE, $this->model->getCurrentSearchEngine());
110  }
111 }