Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractProcessorTest.php
Go to the documentation of this file.
1 <?php
7 
8 class AbstractProcessorTest extends \PHPUnit\Framework\TestCase
9 {
10  const INDEXER_ID = 'stub_indexer_id';
11 
15  protected $model;
16 
21 
22  protected function setUp()
23  {
24  $this->_indexerRegistryMock = $this->createPartialMock(
25  \Magento\Framework\Indexer\IndexerRegistry::class,
26  ['isScheduled', 'get', 'reindexRow', 'reindexList', 'reindexAll', 'invalidate']
27  );
28  $this->model = new \Magento\Indexer\Test\Unit\Model\Indexer\AbstractProcessorStub(
29  $this->_indexerRegistryMock
30  );
31  }
32 
33  public function testGetIndexer()
34  {
35  $this->_indexerRegistryMock->expects($this->once())->method('get')->with(
36  self::INDEXER_ID
37  )->willReturnSelf();
38  $this->model->getIndexer();
39  }
40 
41  public function testReindexAll()
42  {
43  $this->_indexerRegistryMock->expects($this->once())->method('get')->with(
44  self::INDEXER_ID
45  )->willReturnSelf();
46  $this->_indexerRegistryMock->expects($this->once())->method('reindexAll')->willReturnSelf();
47  $this->model->reindexAll();
48  }
49 
50  public function testMarkIndexerAsInvalid()
51  {
52  $this->_indexerRegistryMock->expects($this->once())->method('get')->with(
53  self::INDEXER_ID
54  )->willReturnSelf();
55  $this->_indexerRegistryMock->expects($this->once())->method('invalidate')->willReturnSelf();
56  $this->model->markIndexerAsInvalid();
57  }
58 
59  public function testGetIndexerId()
60  {
61  $this->assertEquals(self::INDEXER_ID, $this->model->getIndexerId());
62  }
63 
68  public function testReindexRow($scheduled)
69  {
70  $id = 1;
71  if ($scheduled) {
72  $this->_indexerRegistryMock->expects($this->once())->method('get')->with(
73  self::INDEXER_ID
74  )->willReturnSelf();
75  $this->_indexerRegistryMock->expects($this->once())->method('isScheduled')->willReturn($scheduled);
76  $this->assertEquals(null, $this->model->reindexRow($id));
77  } else {
78  $this->_indexerRegistryMock->expects($this->exactly(2))->method('get')->with(
79  self::INDEXER_ID
80  )->willReturnSelf();
81  $this->_indexerRegistryMock->expects($this->once())->method('isScheduled')->willReturn($scheduled);
82  $this->_indexerRegistryMock->expects($this->once())->method('reindexRow')->with($id)->willReturnSelf();
83  $this->assertEquals(null, $this->model->reindexRow($id));
84  }
85  }
86 
91  public function testReindexList($scheduled)
92  {
93  $ids = [1];
94  if ($scheduled) {
95  $this->_indexerRegistryMock->expects($this->once())->method('get')->with(
96  self::INDEXER_ID
97  )->willReturnSelf();
98  $this->_indexerRegistryMock->expects($this->once())->method('isScheduled')->willReturn($scheduled);
99  $this->assertEquals(null, $this->model->reindexList($ids));
100  } else {
101  $this->_indexerRegistryMock->expects($this->exactly(2))->method('get')->with(
102  self::INDEXER_ID
103  )->willReturnSelf();
104  $this->_indexerRegistryMock->expects($this->once())->method('isScheduled')->willReturn($scheduled);
105  $this->_indexerRegistryMock->expects($this->once())->method('reindexList')->with($ids)->willReturnSelf();
106  $this->assertEquals(null, $this->model->reindexList($ids));
107  }
108  }
109 
113  public function runDataProvider()
114  {
115  return [
116  [true],
117  [false]
118  ];
119  }
120 
124  public function testIsIndexerScheduled()
125  {
126  $this->_indexerRegistryMock->expects($this->once())->method('get')->with(
128  )->willReturnSelf();
129  $this->_indexerRegistryMock->expects($this->once())->method('isScheduled')->willReturn(false);
130  $this->model->isIndexerScheduled();
131  }
132 }
$id
Definition: fieldset.phtml:14