SynchronizeWebsiteAttributesTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Catalog\Test\Unit\Cron;
  7. use Magento\Catalog\Cron\SynchronizeWebsiteAttributes;
  8. use Magento\Catalog\Model\ResourceModel\Attribute\WebsiteAttributesSynchronizer;
  9. /**
  10. * Class SynchronizeWebsiteAttributesTest
  11. * @package Magento\Catalog\Test\Unit\Cron
  12. */
  13. class SynchronizeWebsiteAttributesTest extends \PHPUnit\Framework\TestCase
  14. {
  15. public function testExecuteSuccess()
  16. {
  17. $synchronizerMock = $this->getMockBuilder(WebsiteAttributesSynchronizer::class)
  18. ->disableOriginalConstructor()
  19. ->setMethods([
  20. 'isSynchronizationRequired',
  21. 'synchronize',
  22. ])
  23. ->getMock();
  24. $synchronizerMock->expects($this->once())
  25. ->method('isSynchronizationRequired')
  26. ->will(
  27. $this->returnValue(true)
  28. );
  29. $synchronizerMock->expects($this->once())
  30. ->method('synchronize');
  31. $cron = new SynchronizeWebsiteAttributes($synchronizerMock);
  32. $cron->execute();
  33. }
  34. public function testExecuteWithNoSyncRequired()
  35. {
  36. $synchronizerMock = $this->getMockBuilder(WebsiteAttributesSynchronizer::class)
  37. ->disableOriginalConstructor()
  38. ->setMethods([
  39. 'isSynchronizationRequired',
  40. 'synchronize',
  41. ])
  42. ->getMock();
  43. $synchronizerMock->expects($this->once())
  44. ->method('isSynchronizationRequired')
  45. ->will(
  46. $this->returnValue(false)
  47. );
  48. $synchronizerMock->expects($this->never())
  49. ->method('synchronize');
  50. $cron = new SynchronizeWebsiteAttributes($synchronizerMock);
  51. $cron->execute();
  52. }
  53. }