ClassMapTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Migration\Handler;
  7. class ClassMapTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @return void
  11. */
  12. public function testHandle()
  13. {
  14. $classOldFashion = 'catalog/product_widget_link';
  15. $classNewStyle = 'Magento\\Catalog\\Block\\Product\\Widget\\Link';
  16. $fieldName = 'fieldname';
  17. /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $record */
  18. $record = $this->createPartialMock(
  19. \Migration\ResourceModel\Record::class,
  20. ['getValue', 'setValue', 'getFields']
  21. );
  22. $record->expects($this->once())->method('getValue')->with($fieldName)->willReturn($classOldFashion);
  23. $record->expects($this->once())->method('setValue')->with($fieldName, $classNewStyle);
  24. $record->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName]));
  25. $record2 = $this->getMockBuilder(\Migration\ResourceModel\Record::class)
  26. ->disableOriginalConstructor()
  27. ->getMock();
  28. $classMap = $this->createPartialMock(
  29. \Migration\Reader\ClassMap::class,
  30. ['convertClassName']
  31. );
  32. $classMap->expects($this->once())
  33. ->method('convertClassName')
  34. ->with($classOldFashion)
  35. ->willReturn($classNewStyle);
  36. $handler = new \Migration\Handler\ClassMap($classMap);
  37. $handler->setField($fieldName);
  38. $handler->handle($record, $record2);
  39. }
  40. }