SetDefaultWebsiteIdTest.php 1.6 KB

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