Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FlushAllCacheObserverTest.php
Go to the documentation of this file.
1 <?php
7 
8 class FlushAllCacheObserverTest extends \PHPUnit\Framework\TestCase
9 {
11  protected $model;
12 
14  protected $observerMock;
15 
17  protected $configMock;
18 
20  protected $purgeCache;
21 
25  protected function setUp()
26  {
27  $this->configMock = $this->createPartialMock(\Magento\PageCache\Model\Config::class, ['getType', 'isEnabled']);
28  $this->purgeCache = $this->createMock(\Magento\CacheInvalidate\Model\PurgeCache::class);
29  $this->model = new \Magento\CacheInvalidate\Observer\FlushAllCacheObserver(
30  $this->configMock,
31  $this->purgeCache
32  );
33  $this->observerMock = $this->createPartialMock(\Magento\Framework\Event\Observer::class, ['getEvent']);
34  }
35 
39  public function testFlushAllCache()
40  {
41  $this->configMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
42  $this->configMock->expects(
43  $this->once()
44  )->method(
45  'getType'
46  )->will(
47  $this->returnValue(\Magento\PageCache\Model\Config::VARNISH)
48  );
49 
50  $this->purgeCache->expects($this->once())->method('sendPurgeRequest')->with('.*');
51  $this->model->execute($this->observerMock);
52  }
53 }