CleanCacheTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Test\Unit\Cron;
  7. class CleanCacheTest extends \PHPUnit\Framework\TestCase
  8. {
  9. public function testCleanCache()
  10. {
  11. $cacheBackendMock = $this->getMockForAbstractClass(\Zend_Cache_Backend_Interface::class);
  12. $cacheFrontendMock = $this->getMockForAbstractClass(\Magento\Framework\Cache\FrontendInterface::class);
  13. $frontendPoolMock = $this->createMock(\Magento\Framework\App\Cache\Frontend\Pool::class);
  14. $cacheBackendMock->expects(
  15. $this->once()
  16. )->method(
  17. 'clean'
  18. )->with(
  19. \Zend_Cache::CLEANING_MODE_OLD,
  20. []
  21. );
  22. $cacheFrontendMock->expects(
  23. $this->once()
  24. )->method(
  25. 'getBackend'
  26. )->will(
  27. $this->returnValue($cacheBackendMock)
  28. );
  29. $frontendPoolMock->expects(
  30. $this->any()
  31. )->method(
  32. 'valid'
  33. )->will(
  34. $this->onConsecutiveCalls(true, false)
  35. );
  36. $frontendPoolMock->expects(
  37. $this->any()
  38. )->method(
  39. 'current'
  40. )->will(
  41. $this->returnValue($cacheFrontendMock)
  42. );
  43. $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  44. /**
  45. * @var \Magento\Backend\Cron\CleanCache
  46. */
  47. $model = $objectManagerHelper->getObject(
  48. \Magento\Backend\Cron\CleanCache::class,
  49. [
  50. 'cacheFrontendPool' => $frontendPoolMock,
  51. ]
  52. );
  53. $model->execute();
  54. }
  55. }