|
5 | 5 | */
|
6 | 6 | namespace Magento\CatalogImportExport\Test\Unit\Model\Indexer\Product\Flat\Plugin;
|
7 | 7 |
|
| 8 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 9 | + |
8 | 10 | class ImportTest extends \PHPUnit\Framework\TestCase
|
9 | 11 | {
|
10 |
| - public function testAfterImportSource() |
| 12 | + /** |
| 13 | + * @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor|\PHPUnit_Framework_MockObject_MockObject |
| 14 | + */ |
| 15 | + private $processorMock; |
| 16 | + |
| 17 | + /** |
| 18 | + * @var \Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin\Import |
| 19 | + */ |
| 20 | + private $model; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var \Magento\Catalog\Model\Indexer\Product\Flat\State|\PHPUnit_Framework_MockObject_MockObject |
| 24 | + */ |
| 25 | + private $flatStateMock; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var \Magento\ImportExport\Model\Import|\PHPUnit_Framework_MockObject_MockObject |
| 29 | + */ |
| 30 | + private $subjectMock; |
| 31 | + |
| 32 | + protected function setUp() |
11 | 33 | {
|
12 |
| - /** |
13 |
| - * @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor| |
14 |
| - * \PHPUnit_Framework_MockObject_MockObject $processorMock |
15 |
| - */ |
16 |
| - $processorMock = $this->createPartialMock( |
17 |
| - \Magento\Catalog\Model\Indexer\Product\Flat\Processor::class, |
18 |
| - ['markIndexerAsInvalid'] |
| 34 | + $this->processorMock = $this->getMockBuilder(\Magento\Catalog\Model\Indexer\Product\Flat\Processor::class) |
| 35 | + ->disableOriginalConstructor() |
| 36 | + ->setMethods(['markIndexerAsInvalid', 'isIndexerScheduled']) |
| 37 | + ->getMock(); |
| 38 | + |
| 39 | + $this->flatStateMock = $this->getMockBuilder(\Magento\Catalog\Model\Indexer\Product\Flat\State::class) |
| 40 | + ->disableOriginalConstructor() |
| 41 | + ->setMethods(['isFlatEnabled']) |
| 42 | + ->getMock(); |
| 43 | + |
| 44 | + $this->subjectMock = $this->getMockBuilder(\Magento\ImportExport\Model\Import::class) |
| 45 | + ->disableOriginalConstructor() |
| 46 | + ->getMock(); |
| 47 | + |
| 48 | + $this->model = (new ObjectManager($this))->getObject( |
| 49 | + \Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin\Import::class, |
| 50 | + [ |
| 51 | + 'productFlatIndexerProcessor' => $this->processorMock, |
| 52 | + 'flatState' => $this->flatStateMock |
| 53 | + ] |
19 | 54 | );
|
| 55 | + } |
20 | 56 |
|
21 |
| - $subjectMock = $this->createMock(\Magento\ImportExport\Model\Import::class); |
22 |
| - $processorMock->expects($this->once())->method('markIndexerAsInvalid'); |
| 57 | + public function testAfterImportSourceWithFlatEnabledAndIndexerScheduledDisabled() |
| 58 | + { |
| 59 | + $this->flatStateMock->expects($this->once())->method('isFlatEnabled')->willReturn(true); |
| 60 | + $this->processorMock->expects($this->once())->method('isIndexerScheduled')->willReturn(false); |
| 61 | + $this->processorMock->expects($this->once())->method('markIndexerAsInvalid'); |
| 62 | + $someData = [1, 2, 3]; |
| 63 | + $this->assertEquals($someData, $this->model->afterImportSource($this->subjectMock, $someData)); |
| 64 | + } |
23 | 65 |
|
| 66 | + public function testAfterImportSourceWithFlatDisabledAndIndexerScheduledDisabled() |
| 67 | + { |
| 68 | + $this->flatStateMock->expects($this->once())->method('isFlatEnabled')->willReturn(false); |
| 69 | + $this->processorMock->expects($this->never())->method('isIndexerScheduled')->willReturn(false); |
| 70 | + $this->processorMock->expects($this->never())->method('markIndexerAsInvalid'); |
24 | 71 | $someData = [1, 2, 3];
|
| 72 | + $this->assertEquals($someData, $this->model->afterImportSource($this->subjectMock, $someData)); |
| 73 | + } |
25 | 74 |
|
26 |
| - $model = new \Magento\CatalogImportExport\Model\Indexer\Product\Flat\Plugin\Import($processorMock); |
27 |
| - $this->assertEquals($someData, $model->afterImportSource($subjectMock, $someData)); |
| 75 | + public function testAfterImportSourceWithFlatEnabledAndIndexerScheduledEnabled() |
| 76 | + { |
| 77 | + $this->flatStateMock->expects($this->once())->method('isFlatEnabled')->willReturn(true); |
| 78 | + $this->processorMock->expects($this->once())->method('isIndexerScheduled')->willReturn(true); |
| 79 | + $this->processorMock->expects($this->never())->method('markIndexerAsInvalid'); |
| 80 | + $someData = [1, 2, 3]; |
| 81 | + $this->assertEquals($someData, $this->model->afterImportSource($this->subjectMock, $someData)); |
28 | 82 | }
|
29 | 83 | }
|
0 commit comments