CronTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\NewRelicReporting\Test\Unit\Model;
  7. use Magento\NewRelicReporting\Model\Cron;
  8. /**
  9. * Class CronTest
  10. */
  11. class CronTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\NewRelicReporting\Model\Cron
  15. */
  16. protected $model;
  17. /**
  18. * @var \Magento\NewRelicReporting\Model\Config|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $configMock;
  21. /**
  22. * @var \Magento\NewRelicReporting\Model\Cron\ReportModulesInfo|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $reportModulesInfoMock;
  25. /**
  26. * @var \Magento\NewRelicReporting\Model\Cron\ReportCounts|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $reportCountsMock;
  29. /**
  30. * @var \Magento\NewRelicReporting\Model\Cron\ReportNewRelicCron|\PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $reportNewRelicCronMock;
  33. protected function setUp()
  34. {
  35. $this->configMock = $this->getMockBuilder(\Magento\NewRelicReporting\Model\Config::class)
  36. ->setMethods(['isCronEnabled'])
  37. ->disableOriginalConstructor()
  38. ->getMock();
  39. $this->reportModulesInfoMock = $this->getMockBuilder(
  40. \Magento\NewRelicReporting\Model\Cron\ReportModulesInfo::class
  41. )->disableOriginalConstructor()
  42. ->getMock();
  43. $this->reportCountsMock = $this->getMockBuilder(\Magento\NewRelicReporting\Model\Cron\ReportCounts::class)
  44. ->disableOriginalConstructor()
  45. ->getMock();
  46. $this->reportNewRelicCronMock = $this->getMockBuilder(
  47. \Magento\NewRelicReporting\Model\Cron\ReportNewRelicCron::class
  48. )->disableOriginalConstructor()
  49. ->getMock();
  50. $this->model = new Cron(
  51. $this->configMock,
  52. $this->reportModulesInfoMock,
  53. $this->reportCountsMock,
  54. $this->reportNewRelicCronMock
  55. );
  56. }
  57. /**
  58. * Test case when cron is disabled in config
  59. *
  60. * @return \Magento\NewRelicReporting\Model\Cron
  61. */
  62. public function testRunCronCronDisabledFromConfig()
  63. {
  64. $this->configMock->expects($this->once())
  65. ->method('isCronEnabled')
  66. ->willReturn(false);
  67. $this->assertSame(
  68. $this->model,
  69. $this->model->runCron()
  70. );
  71. }
  72. /**
  73. * Test case when cron is enabled in config
  74. *
  75. * @return \Magento\NewRelicReporting\Model\Cron
  76. */
  77. public function testRunCronCronEnabledFromConfig()
  78. {
  79. $this->configMock->expects($this->once())
  80. ->method('isCronEnabled')
  81. ->willReturn(true);
  82. $this->reportModulesInfoMock->expects($this->once())
  83. ->method('report')
  84. ->willReturnSelf();
  85. $this->reportCountsMock->expects($this->once())
  86. ->method('report')
  87. ->willReturnSelf();
  88. $this->reportNewRelicCronMock->expects($this->once())
  89. ->method('report')
  90. ->willReturnSelf();
  91. $this->assertSame(
  92. $this->model,
  93. $this->model->runCron()
  94. );
  95. }
  96. }