SetValueTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Migration\Handler;
  7. class SetValueTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @return void
  11. */
  12. public function testHandle()
  13. {
  14. $value = 'value';
  15. $fieldName = 'fieldname';
  16. /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $record */
  17. $record = $this->createPartialMock(
  18. \Migration\ResourceModel\Record::class,
  19. ['setValue', 'getFields']
  20. );
  21. $record->expects($this->once())->method('setValue')->with($fieldName, $value);
  22. $record->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName]));
  23. $record2 = $this->getMockBuilder(\Migration\ResourceModel\Record::class)
  24. ->disableOriginalConstructor()
  25. ->getMock();
  26. $handler = new SetValue($value);
  27. $handler->setField($fieldName);
  28. $handler->handle($record, $record2);
  29. }
  30. /**
  31. * @return void
  32. */
  33. public function testHandleException()
  34. {
  35. $value = 'value';
  36. $record = $this->createPartialMock(
  37. \Migration\ResourceModel\Record::class,
  38. ['getFields']
  39. );
  40. $record->expects($this->once())->method('getFields')->will($this->returnValue([]));
  41. $handler = new SetValue($value);
  42. $record2 = $this->getMockBuilder(\Migration\ResourceModel\Record::class)
  43. ->disableOriginalConstructor()
  44. ->getMock();
  45. $this->expectException('Exception');
  46. $handler->handle($record, $record2);
  47. }
  48. }