Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InvalidateCacheTest.php
Go to the documentation of this file.
1 <?php
8 
9 class InvalidateCacheTest extends \PHPUnit\Framework\TestCase
10 {
12  protected $_model;
13 
15  protected $_configMock;
16 
18  protected $_typeListMock;
19 
23  protected $observerMock;
24 
28  protected function setUp()
29  {
30  $this->_configMock = $this->createPartialMock(\Magento\PageCache\Model\Config::class, ['getType', 'isEnabled']);
31  $this->_typeListMock = $this->createMock(\Magento\Framework\App\Cache\TypeList::class);
32 
33  $this->observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
34 
35  $this->_model = new \Magento\PageCache\Observer\InvalidateCache(
36  $this->_configMock,
37  $this->_typeListMock
38  );
39  }
40 
45  public function testExecute($cacheState)
46  {
47  $this->_configMock->expects($this->once())->method('isEnabled')->will($this->returnValue($cacheState));
48 
49  if ($cacheState) {
50  $this->_typeListMock->expects($this->once())->method('invalidate')->with($this->equalTo('full_page'));
51  }
52 
53  $this->_model->execute($this->observerMock);
54  }
55 
59  public function invalidateCacheDataProvider()
60  {
61  return [[true], [false]];
62  }
63 }