GetEventStatusTest.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 Migration\Handler;
  7. use Magento\Indexer\Model\Processor\Handler;
  8. use Migration\ResourceModel\Record;
  9. /**
  10. * Class GetDestinationValueTest
  11. */
  12. class GetEventStatusTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @return void
  16. * @dataProvider eventDatesDataProvider
  17. * @param string $dateStart
  18. * @param string $dateEnd
  19. * @param int $status
  20. */
  21. public function testHandle($dateStart, $dateEnd, $status)
  22. {
  23. /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $record */
  24. $record = $this->getMockBuilder(\Migration\ResourceModel\Record::class)
  25. ->setMethods(['setValue', 'getValue', 'getFields'])
  26. ->getMock();
  27. $record->expects($this->any())->method('getFields')->willReturn(['status']);
  28. $record->expects($this->any())->method('getValue')->willReturnMap(
  29. [
  30. ['date_start', $dateStart],
  31. ['date_end', $dateEnd]
  32. ]
  33. );
  34. $record->expects($this->once())->method('setValue')->with('status', $status);
  35. $record2 = $this->getMockBuilder(\Migration\ResourceModel\Record::class)
  36. ->disableOriginalConstructor()
  37. ->getMock();
  38. $handler = new GetEventStatus();
  39. $handler->setField('status');
  40. $handler->handle($record, $record2);
  41. }
  42. /**
  43. * @return array
  44. */
  45. public function eventDatesDataProvider()
  46. {
  47. return [
  48. 'closed' => [
  49. 'date_start' => date('Y-m-d H:i:s', strtotime('-5 days')),
  50. 'date_end' => date('Y-m-d H:i:s', strtotime('-2 days')),
  51. 'status' => GetEventStatus::EVENT_CLOSED
  52. ],
  53. 'open' => [
  54. 'date_start' => date('Y-m-d H:i:s', strtotime('-1 days')),
  55. 'date_end' => date('Y-m-d H:i:s', strtotime('+2 days')),
  56. 'status' => GetEventStatus::EVENT_OPEN
  57. ],
  58. 'upcoming' => [
  59. 'date_start' => date('Y-m-d H:i:s', strtotime('+2 days')),
  60. 'date_end' => date('Y-m-d H:i:s', strtotime('+5 days')),
  61. 'status' => GetEventStatus::EVENT_UPCOMING
  62. ]
  63. ];
  64. }
  65. }