AggregateSalesReportCouponsDataTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SalesRule\Test\Unit\Cron;
  7. class AggregateSalesReportCouponsDataTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\SalesRule\Cron\AggregateSalesReportCouponsData|\PHPUnit_Framework_MockObject_MockObject
  11. */
  12. protected $model;
  13. /**
  14. * @var \Magento\Framework\Locale\Resolver|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $localeResolver;
  17. /**
  18. * @var \Magento\Framework\Stdlib\DateTime\Timezone|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $localeDate;
  21. /**
  22. * @var \Magento\SalesRule\Model\ResourceModel\Report\Rule|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $reportRule;
  25. protected function setUp()
  26. {
  27. $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  28. $this->initMocks();
  29. $this->model = $helper->getObject(
  30. \Magento\SalesRule\Cron\AggregateSalesReportCouponsData::class,
  31. [
  32. 'reportRule' => $this->reportRule,
  33. 'localeResolver' => $this->localeResolver,
  34. 'localeDate' => $this->localeDate,
  35. ]
  36. );
  37. }
  38. protected function initMocks()
  39. {
  40. $this->localeResolver = $this->createMock(\Magento\Framework\Locale\Resolver::class);
  41. $this->localeDate = $this->createPartialMock(\Magento\Framework\Stdlib\DateTime\Timezone::class, ['date']);
  42. $this->reportRule = $this->createMock(\Magento\SalesRule\Model\ResourceModel\Report\Rule::class);
  43. }
  44. public function testExecute()
  45. {
  46. $data = new \DateTime();
  47. $this->localeResolver->expects($this->once())
  48. ->method('emulate')
  49. ->with(0);
  50. $this->localeDate->expects($this->once())
  51. ->method('date')
  52. ->will($this->returnValue($data));
  53. $this->reportRule->expects($this->once())
  54. ->method('aggregate')
  55. ->with($data);
  56. $this->localeResolver->expects($this->once())
  57. ->method('revert');
  58. $scheduleMock = $this->createMock(\Magento\Cron\Model\Schedule::class);
  59. $this->assertEquals($this->model, $this->model->execute($scheduleMock));
  60. }
  61. }