Example #1
0
 public function testGetNegative()
 {
     $engineMock = $this->getMock('Magento\\CatalogSearch\\Model\\Resource\\Fulltext\\Engine', array('test', '__wakeup'), array(), '', false);
     $engineMock->expects($this->never())->method('test');
     $this->_scopeConfigMock->expects($this->once())->method('getValue')->with('catalog/search/engine')->will($this->returnValue(''));
     $this->_engineFactoryMock->expects($this->once())->method('create')->with('Magento\\CatalogSearch\\Model\\Resource\\Fulltext\\Engine')->will($this->returnValue($engineMock));
     $this->assertEquals($engineMock, $this->_model->get());
 }
Example #2
0
 /**
  * Get engine singleton
  *
  * @return \Magento\CatalogSearch\Model\Resource\EngineInterface
  */
 public function get()
 {
     if (!$this->_engine) {
         $engineClassName = $this->_scopeConfig->getValue('catalog/search/engine', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
         /**
          * This needed if there already was saved in configuration some none-default engine
          * and module of that engine was disabled after that.
          * Problem is in this engine in database configuration still set.
          */
         if ($engineClassName) {
             $engine = $this->_engineFactory->create($engineClassName);
             if ($engine && $engine->test()) {
                 $this->_engine = $engine;
             }
         }
         if (!$this->_engine) {
             $this->_engine = $this->_engineFactory->create('Magento\\CatalogSearch\\Model\\Resource\\Fulltext\\Engine');
         }
     }
     return $this->_engine;
 }