AddPrefixTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Migration\Handler;
  7. /**
  8. * Class AddPrefixTest
  9. */
  10. class AddPrefixTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @return void
  14. */
  15. public function testHandle()
  16. {
  17. $prefix = 'prefix';
  18. $fieldName = 'fieldname';
  19. /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */
  20. $recordToHandle = $this->getMockBuilder(\Migration\ResourceModel\Record::class)
  21. ->setMethods(['getValue', 'setValue', 'getFields'])
  22. ->disableOriginalConstructor()
  23. ->getMock();
  24. $recordToHandle->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName]));
  25. $recordToHandle->expects($this->once())->method('getValue')->with($fieldName)->will($this->returnValue('val'));
  26. $recordToHandle->expects($this->once())->method('setValue')->with($fieldName, $prefix . 'val');
  27. $oppositeRecord = $this->getMockBuilder(\Migration\ResourceModel\Record::class)
  28. ->disableOriginalConstructor()
  29. ->getMock();
  30. $handler = new AddPrefix($prefix);
  31. $handler->setField($fieldName);
  32. $handler->handle($recordToHandle, $oppositeRecord);
  33. }
  34. }