CleanCacheTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Indexer\Test\Unit\Model\Processor;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. use Magento\Indexer\Model\Processor\CleanCache;
  9. class CleanCacheTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * Tested plugin
  13. *
  14. * @var \Magento\Indexer\Model\Processor\CleanCache
  15. */
  16. protected $plugin;
  17. /**
  18. * Mock for context
  19. *
  20. * @var \Magento\Framework\Indexer\CacheContext|\PHPUnit_Framework_MockObject_MockObject
  21. */
  22. protected $contextMock;
  23. /**
  24. * Subject mock
  25. *
  26. * @var \Magento\Framework\Indexer\ActionInterface|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $subjectMock;
  29. /**
  30. * Event manager mock
  31. *
  32. * @var \Magento\Framework\Event\Manager|\PHPUnit_Framework_MockObject_MockObject
  33. */
  34. protected $eventManagerMock;
  35. /**
  36. * Cache mock
  37. *
  38. * @var \Magento\Framework\App\CacheInterface|\PHPUnit_Framework_MockObject_MockObject
  39. */
  40. protected $cacheMock;
  41. /**
  42. * @var ObjectManager
  43. */
  44. protected $objectManager;
  45. /**
  46. * Set up
  47. */
  48. protected function setUp()
  49. {
  50. $this->objectManager = new ObjectManager($this);
  51. $this->subjectMock = $this->createMock(\Magento\Indexer\Model\Processor::class);
  52. $this->contextMock = $this->createMock(\Magento\Framework\Indexer\CacheContext::class);
  53. $this->eventManagerMock = $this->createMock(\Magento\Framework\Event\Manager::class);
  54. $this->cacheMock = $this->createMock(\Magento\Framework\App\CacheInterface::class);
  55. $this->plugin = new CleanCache(
  56. $this->contextMock,
  57. $this->eventManagerMock
  58. );
  59. $this->objectManager->setBackwardCompatibleProperty(
  60. $this->plugin,
  61. 'cache',
  62. $this->cacheMock
  63. );
  64. }
  65. /**
  66. * Test afterUpdateMview
  67. *
  68. * @return void
  69. */
  70. public function testAfterUpdateMview()
  71. {
  72. $tags = ['tag_name1', 'tag_name2'];
  73. $this->eventManagerMock->expects($this->once())
  74. ->method('dispatch')
  75. ->with(
  76. $this->equalTo('clean_cache_after_reindex'),
  77. $this->equalTo(['object' => $this->contextMock])
  78. );
  79. $this->contextMock->expects($this->atLeastOnce())
  80. ->method('getIdentities')
  81. ->willReturn($tags);
  82. $this->cacheMock->expects($this->once())
  83. ->method('clean')
  84. ->with($tags);
  85. $this->plugin->afterUpdateMview($this->subjectMock);
  86. }
  87. }