Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
JobTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class JobTest extends \PHPUnit\Framework\TestCase
11 {
19  public function testApplyAll()
20  {
21  $ruleProcessorMock = $this->createPartialMock(
22  \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor::class,
23  ['markIndexerAsInvalid']
24  );
25  $ruleProcessorMock->expects($this->once())->method('markIndexerAsInvalid');
26  $jobModel = new Job($ruleProcessorMock);
27  $jobModel->applyAll();
28  }
29 
33  public function testExceptionApplyAll()
34  {
35  $ruleProcessorMock = $this->createPartialMock(
36  \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor::class,
37  ['markIndexerAsInvalid']
38  );
39  $exceptionMessage = 'Test exception message';
40  $exceptionCallback = function () use ($exceptionMessage) {
41  throw new \Magento\Framework\Exception\LocalizedException(__($exceptionMessage));
42  };
43  $ruleProcessorMock->expects($this->once())
44  ->method('markIndexerAsInvalid')
45  ->will($this->returnCallback($exceptionCallback));
46  $jobModel = new Job($ruleProcessorMock);
47  $jobModel->applyAll();
48  $this->assertEquals($exceptionMessage, $jobModel->getError());
49  }
50 }
__()
Definition: __.php:13