Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FlushAllCacheTest.php
Go to the documentation of this file.
1 <?php
9 
10 class FlushAllCacheTest extends \PHPUnit\Framework\TestCase
11 {
13  private $_model;
14 
16  private $_configMock;
17 
19  private $_cacheMock;
20 
22  private $observerMock;
23 
25  private $fullPageCacheMock;
26 
30  protected function setUp()
31  {
32  $this->_configMock = $this->createPartialMock(\Magento\PageCache\Model\Config::class, ['getType', 'isEnabled']);
33  $this->_cacheMock = $this->createPartialMock(\Magento\Framework\App\PageCache\Cache::class, ['clean']);
34  $this->fullPageCacheMock = $this->createPartialMock(\Magento\PageCache\Model\Cache\Type::class, ['clean']);
35  $this->observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
36 
37  $this->_model = new \Magento\PageCache\Observer\FlushAllCache(
38  $this->_configMock,
39  $this->_cacheMock
40  );
41 
42  $reflection = new \ReflectionClass(\Magento\PageCache\Observer\FlushAllCache::class);
43  $reflectionProperty = $reflection->getProperty('fullPageCache');
44  $reflectionProperty->setAccessible(true);
45  $reflectionProperty->setValue($this->_model, $this->fullPageCacheMock);
46  }
47 
51  public function testExecute()
52  {
53  $this->_configMock->expects(
54  $this->once()
55  )->method(
56  'getType'
57  )->will(
58  $this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN)
59  );
60 
61  $this->fullPageCacheMock->expects($this->once())->method('clean');
62  $this->_model->execute($this->observerMock);
63  }
64 }