Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PriceScopeTest.php
Go to the documentation of this file.
1 <?php
7 
8 class PriceScopeTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_objectManager;
14 
18  protected $_model;
19 
23  protected $_indexerMock;
24 
29 
30  protected function setUp()
31  {
32  $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
33 
34  $this->_indexerMock = $this->createPartialMock(\Magento\Indexer\Model\Indexer::class, ['load', 'invalidate']);
35  $this->indexerRegistryMock = $this->createPartialMock(
36  \Magento\Framework\Indexer\IndexerRegistry::class,
37  ['get']
38  );
39 
40  $contextMock = $this->createMock(\Magento\Framework\Model\Context::class);
41  $registryMock = $this->createMock(\Magento\Framework\Registry::class);
42  $storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
43  $configMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
44 
45  $this->_model = $this->_objectManager->getObject(
46  \Magento\Catalog\Model\Indexer\Product\Price\System\Config\PriceScope::class,
47  [
48  'context' => $contextMock,
49  'registry' => $registryMock,
50  'storeManager' => $storeManagerMock,
51  'config' => $configMock,
52  'indexerRegistry' => $this->indexerRegistryMock
53  ]
54  );
55  }
56 
57  public function testProcessValue()
58  {
59  $this->_indexerMock->expects($this->once())->method('invalidate');
60  $this->prepareIndexer(1);
61  $this->_model->setValue('1');
62  $this->_model->processValue();
63  }
64 
65  public function testProcessValueNotChanged()
66  {
67  $this->_indexerMock->expects($this->never())->method('invalidate');
68  $this->prepareIndexer(0);
69  $this->_model->processValue();
70  }
71 
75  protected function prepareIndexer($countCall)
76  {
77  $this->indexerRegistryMock->expects($this->exactly($countCall))
78  ->method('get')
79  ->with(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)
80  ->will($this->returnValue($this->_indexerMock));
81  }
82 }