FlushAllCacheTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\PageCache\Test\Unit\Observer;
  8. class FlushAllCacheTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var \Magento\PageCache\Observer\FlushAllCache */
  11. private $_model;
  12. /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\PageCache\Model\Config */
  13. private $_configMock;
  14. /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\PageCache\Cache */
  15. private $_cacheMock;
  16. /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Event\Observer */
  17. private $observerMock;
  18. /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\PageCache\Model\Cache\Type */
  19. private $fullPageCacheMock;
  20. /**
  21. * Set up all mocks and data for test
  22. */
  23. protected function setUp()
  24. {
  25. $this->_configMock = $this->createPartialMock(\Magento\PageCache\Model\Config::class, ['getType', 'isEnabled']);
  26. $this->_cacheMock = $this->createPartialMock(\Magento\Framework\App\PageCache\Cache::class, ['clean']);
  27. $this->fullPageCacheMock = $this->createPartialMock(\Magento\PageCache\Model\Cache\Type::class, ['clean']);
  28. $this->observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
  29. $this->_model = new \Magento\PageCache\Observer\FlushAllCache(
  30. $this->_configMock,
  31. $this->_cacheMock
  32. );
  33. $reflection = new \ReflectionClass(\Magento\PageCache\Observer\FlushAllCache::class);
  34. $reflectionProperty = $reflection->getProperty('fullPageCache');
  35. $reflectionProperty->setAccessible(true);
  36. $reflectionProperty->setValue($this->_model, $this->fullPageCacheMock);
  37. }
  38. /**
  39. * Test case for flushing all the cache
  40. */
  41. public function testExecute()
  42. {
  43. $this->_configMock->expects(
  44. $this->once()
  45. )->method(
  46. 'getType'
  47. )->will(
  48. $this->returnValue(\Magento\PageCache\Model\Config::BUILT_IN)
  49. );
  50. $this->fullPageCacheMock->expects($this->once())->method('clean');
  51. $this->_model->execute($this->observerMock);
  52. }
  53. }