Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExecuteTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Catalog\Plugin\Model\Indexer\Category\Product\Execute;
10 
11 class ExecuteTest extends \PHPUnit\Framework\TestCase
12 {
14  protected $execute;
15 
17  protected $config;
18 
20  protected $typeList;
21 
22  protected function setUp()
23  {
24  $this->config = $this->getMockBuilder(\Magento\PageCache\Model\Config::class)
25  ->disableOriginalConstructor()
26  ->setMethods(['isEnabled'])
27  ->getMock();
28  $this->typeList = $this->getMockBuilder(\Magento\Framework\App\Cache\TypeListInterface::class)
29  ->disableOriginalConstructor()
30  ->setMethods(['invalidate'])
31  ->getMockForAbstractClass();
32 
33  $this->execute = new Execute($this->config, $this->typeList);
34  }
35 
36  public function testAfterExecute()
37  {
38  $subject = $this->getMockBuilder(\Magento\Catalog\Model\Indexer\Category\Product\AbstractAction::class)
39  ->disableOriginalConstructor()
40  ->getMockForAbstractClass();
41 
42  $result = $this->getMockBuilder(\Magento\Catalog\Model\Indexer\Category\Product\AbstractAction::class)
43  ->disableOriginalConstructor()
44  ->getMockForAbstractClass();
45 
46  $this->config->expects($this->once())
47  ->method('isEnabled')
48  ->willReturn(false);
49  $this->typeList->expects($this->never())
50  ->method('invalidate');
51 
52  $this->assertEquals(
53  $result,
54  $this->execute->afterExecute($subject, $result)
55  );
56  }
57 
58  public function testAfterExecuteInvalidate()
59  {
60  $subject = $this->getMockBuilder(\Magento\Catalog\Model\Indexer\Category\Product\AbstractAction::class)
61  ->disableOriginalConstructor()
62  ->getMockForAbstractClass();
63 
64  $result = $this->getMockBuilder(\Magento\Catalog\Model\Indexer\Category\Product\AbstractAction::class)
65  ->disableOriginalConstructor()
66  ->getMockForAbstractClass();
67 
68  $this->config->expects($this->once())
69  ->method('isEnabled')
70  ->willReturn(true);
71  $this->typeList->expects($this->once())
72  ->method('invalidate')
73  ->with('full_page');
74 
75  $this->assertEquals(
76  $result,
77  $this->execute->afterExecute($subject, $result)
78  );
79  }
80 }