GetDestinationValueTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Migration\Handler;
  7. use Migration\ResourceModel\Record;
  8. /**
  9. * Class GetDestinationValueTest
  10. */
  11. class GetDestinationValueTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @return void
  15. */
  16. public function testHandleSetNull()
  17. {
  18. $fieldName = 'fieldname';
  19. /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */
  20. $recordToHandle = $this->createPartialMock(
  21. \Migration\ResourceModel\Record::class,
  22. ['setValue', 'getFields']
  23. );
  24. $recordToHandle->expects($this->once())->method('setValue')->with($fieldName, null);
  25. $recordToHandle->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName]));
  26. $oppositeRecord = $this->getMockBuilder(\Migration\ResourceModel\Record::class)
  27. ->setMethods(['getValue'])
  28. ->disableOriginalConstructor()
  29. ->getMock();
  30. $oppositeRecord->expects($this->exactly(2))->method('getValue')
  31. ->with($fieldName)
  32. ->will($this->returnValue(null));
  33. $handler = new GetDestinationValue('true');
  34. $handler->setField($fieldName);
  35. $handler->handle($recordToHandle, $oppositeRecord);
  36. }
  37. /**
  38. * @return void
  39. */
  40. public function testHandleSetValue()
  41. {
  42. $value = 'value';
  43. $fieldName = 'fieldname';
  44. /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */
  45. $recordToHandle = $this->createPartialMock(
  46. \Migration\ResourceModel\Record::class,
  47. ['setValue', 'getFields']
  48. );
  49. $recordToHandle->expects($this->once())->method('setValue')->with($fieldName, $value);
  50. $recordToHandle->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName]));
  51. $oppositeRecord = $this->getMockBuilder(\Migration\ResourceModel\Record::class)
  52. ->setMethods(['getValue'])
  53. ->disableOriginalConstructor()
  54. ->getMock();
  55. $oppositeRecord->expects($this->exactly(2))->method('getValue')->with($fieldName)
  56. ->will($this->returnValue($value));
  57. $handler = new GetDestinationValue('true');
  58. $handler->setField($fieldName);
  59. $handler->handle($recordToHandle, $oppositeRecord);
  60. }
  61. /**
  62. * @return void
  63. */
  64. public function testHandleKeepValueFromSource()
  65. {
  66. $fieldName = 'fieldname';
  67. /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */
  68. $recordToHandle = $this->createPartialMock(
  69. \Migration\ResourceModel\Record::class,
  70. ['setValue', 'getFields']
  71. );
  72. $recordToHandle->expects($this->never())->method('setValue');
  73. $recordToHandle->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName]));
  74. $oppositeRecord = $this->getMockBuilder(\Migration\ResourceModel\Record::class)
  75. ->setMethods(['getValue'])
  76. ->disableOriginalConstructor()
  77. ->getMock();
  78. $oppositeRecord->expects($this->once())->method('getValue')->with($fieldName)->will($this->returnValue(null));
  79. $handler = new GetDestinationValue();
  80. $handler->setField($fieldName);
  81. $handler->handle($recordToHandle, $oppositeRecord);
  82. }
  83. }