Exemplo n.º 1
0
 /**
  * @param bool $value
  * @dataProvider executeDataProvider
  */
 public function testLaunch($value)
 {
     $process = $this->getMock('Magento\\Index\\Model\\Process', array('getIndexer', 'reindexEverything', '__wakeup'), array(), '', false);
     $indexer = $this->getMock('Magento\\Index\\Model\\Indexer', array('getProcessesCollection'), array(), '', false);
     $indexerInterface = $this->getMock('Magento\\Index\\Model\\IndexerInterface');
     $this->_indexFactoryMock->expects($this->once())->method('create')->will($this->returnValue($indexer));
     $indexer->expects($this->once())->method('getProcessesCollection')->will($this->returnValue(array($process)));
     $process->expects($this->any())->method('getIndexer')->will($this->returnValue($indexerInterface));
     if ($value) {
         $indexerInterface->expects($this->once())->method('isVisible')->will($this->returnValue(true));
         $process->expects($this->once())->method('reindexEverything');
     } else {
         $indexerInterface->expects($this->once())->method('isVisible')->will($this->returnValue(false));
         $process->expects($this->never())->method('reindexEverything');
     }
     $this->assertEquals($this->_responseMock, $this->_entryPoint->launch());
 }
Exemplo n.º 2
0
 /**
  * Run application
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function launch()
 {
     /* Clean reports */
     $directory = $this->_filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::ROOT_DIR);
     $path = $directory->getRelativePath($this->_reportDir);
     if ($directory->isExist($path)) {
         $directory->delete($path);
     }
     /* Run all indexer processes */
     /** @var $indexer \Magento\Index\Model\Indexer */
     $indexer = $this->_indexerFactory->create();
     /** @var $process \Magento\Index\Model\Process */
     foreach ($indexer->getProcessesCollection() as $process) {
         if ($process->getIndexer()->isVisible()) {
             $process->reindexEverything();
         }
     }
     $this->_response->setCode(0);
     return $this->_response;
 }
Exemplo n.º 3
0
 /**
  * @param bool $value
  * @dataProvider executeDataProvider
  */
 public function testLaunch($value)
 {
     $dir = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', [], [], '', false);
     $dir->expects($this->any())->method('getRelativePath')->will($this->returnArgument(0));
     $this->_filesystem->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($dir));
     $process = $this->getMock('Magento\\Index\\Model\\Process', ['getIndexer', 'reindexEverything', '__wakeup'], [], '', false);
     $indexer = $this->getMock('Magento\\Index\\Model\\Indexer', array('getProcessesCollection'), [], '', false);
     $indexerInterface = $this->getMock('Magento\\Index\\Model\\IndexerInterface');
     $this->_indexFactory->expects($this->once())->method('create')->will($this->returnValue($indexer));
     $indexer->expects($this->once())->method('getProcessesCollection')->will($this->returnValue(array($process)));
     $process->expects($this->any())->method('getIndexer')->will($this->returnValue($indexerInterface));
     if ($value) {
         $indexerInterface->expects($this->once())->method('isVisible')->will($this->returnValue(true));
         $process->expects($this->once())->method('reindexEverything');
     } else {
         $indexerInterface->expects($this->once())->method('isVisible')->will($this->returnValue(false));
         $process->expects($this->never())->method('reindexEverything');
     }
     $this->assertEquals($this->_response, $this->_entryPoint->launch());
 }
Exemplo n.º 4
0
 /**
  * Get Indexer strategy object
  *
  * @throws \Magento\Framework\Model\Exception
  * @return \Magento\Index\Model\IndexerInterface
  */
 public function getIndexer()
 {
     if ($this->_currentIndexer === null) {
         $name = $this->_getData('indexer_code');
         if (!$name) {
             throw new \Magento\Framework\Model\Exception(__('Indexer name is not defined.'));
         }
         $indexerConfiguration = $this->_indexerConfig->getIndexer($name);
         if (!$indexerConfiguration || empty($indexerConfiguration['instance'])) {
             throw new \Magento\Framework\Model\Exception(__('Indexer model is not defined.'));
         }
         $indexerModel = $this->_indexerFactory->create($indexerConfiguration['instance']);
         if ($indexerModel instanceof \Magento\Index\Model\Indexer\AbstractIndexer) {
             $this->_currentIndexer = $indexerModel;
         } else {
             throw new \Magento\Framework\Model\Exception(__('Indexer model should extend \\Magento\\Index\\Model\\Indexer\\Abstract.'));
         }
     }
     return $this->_currentIndexer;
 }