FlushAllCacheObserverTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CacheInvalidate\Test\Unit\Observer;
  7. class FlushAllCacheObserverTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\CacheInvalidate\Observer\FlushAllCacheObserver */
  10. protected $model;
  11. /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Event\Observer */
  12. protected $observerMock;
  13. /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\PageCache\Model\Config */
  14. protected $configMock;
  15. /** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\CacheInvalidate\Model\PurgeCache */
  16. protected $purgeCache;
  17. /**
  18. * Set up all mocks and data for test
  19. */
  20. protected function setUp()
  21. {
  22. $this->configMock = $this->createPartialMock(\Magento\PageCache\Model\Config::class, ['getType', 'isEnabled']);
  23. $this->purgeCache = $this->createMock(\Magento\CacheInvalidate\Model\PurgeCache::class);
  24. $this->model = new \Magento\CacheInvalidate\Observer\FlushAllCacheObserver(
  25. $this->configMock,
  26. $this->purgeCache
  27. );
  28. $this->observerMock = $this->createPartialMock(\Magento\Framework\Event\Observer::class, ['getEvent']);
  29. }
  30. /**
  31. * Test case for flushing all the cache
  32. */
  33. public function testFlushAllCache()
  34. {
  35. $this->configMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
  36. $this->configMock->expects(
  37. $this->once()
  38. )->method(
  39. 'getType'
  40. )->will(
  41. $this->returnValue(\Magento\PageCache\Model\Config::VARNISH)
  42. );
  43. $this->purgeCache->expects($this->once())->method('sendPurgeRequest')->with('.*');
  44. $this->model->execute($this->observerMock);
  45. }
  46. }