Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IndexerTest.php
Go to the documentation of this file.
1 <?php
7 
8 class IndexerTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $entryPoint;
14 
18  protected $processor;
19 
23  protected $filesystem;
24 
28  protected $_response;
29 
30  protected function setUp()
31  {
32  $this->filesystem = $this->createPartialMock(\Magento\Framework\Filesystem::class, ['getDirectoryWrite']);
33  $this->processor = $this->createMock(\Magento\Indexer\Model\Processor::class);
34  $this->_response = $this->createPartialMock(
35  \Magento\Framework\App\Console\Response::class,
36  ['setCode', 'getCode']
37  );
38 
39  $this->entryPoint = new \Magento\Indexer\App\Indexer(
40  'reportDir',
41  $this->filesystem,
42  $this->processor,
43  $this->_response
44  );
45  }
46 
52  public function testExecute($isExist, $callCount)
53  {
54  $this->_response->expects($this->once())->method('setCode')->with(0);
55  $this->_response->expects($this->once())->method('getCode')->will($this->returnValue(0));
56  $dir = $this->createMock(\Magento\Framework\Filesystem\Directory\Write::class);
57  $dir->expects($this->any())->method('getRelativePath')->will($this->returnArgument(0));
58  $dir->expects($this->once())->method('isExist')->will($this->returnValue($isExist));
59  $dir->expects($this->exactly($callCount))->method('delete')->will($this->returnValue(true));
60  $this->filesystem->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($dir));
61  $this->processor->expects($this->once())->method('reindexAll');
62  $this->assertEquals(0, $this->entryPoint->launch()->getCode());
63  }
64 
68  public function executeProvider()
69  {
70  return [
71  'set1' => ['isExist' => true, 'expectsValue' => 1],
72  'set1' => ['delete' => false, 'expectsValue' => 0]
73  ];
74  }
75 
76  public function testCatchException()
77  {
78  $bootstrap = $this->createMock(\Magento\Framework\App\Bootstrap::class);
79  $this->assertFalse($this->entryPoint->catchException($bootstrap, new \Exception()));
80  }
81 }
if(defined('TESTS_MAGENTO_INSTALLATION') &&TESTS_MAGENTO_INSTALLATION==='enabled') $bootstrap
Definition: bootstrap.php:73