ConvertIpTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Migration\Handler;
  7. class ConvertIpTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @return void
  11. */
  12. public function testHandle()
  13. {
  14. $ip = '127.0.0.1';
  15. $ipDbValue = inet_pton($ip);
  16. $fieldName = 'fieldname';
  17. /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $record */
  18. $record = $this->createPartialMock(
  19. \Migration\ResourceModel\Record::class,
  20. ['setValue', 'getValue', 'getFields']
  21. );
  22. $record->expects($this->any())->method('getFields')->willReturn([$fieldName]);
  23. $record->expects($this->any())->method('getValue')->with($fieldName)->willReturn($ipDbValue);
  24. $record->expects($this->any())->method('setValue')->with($fieldName, ip2long(inet_ntop($ipDbValue)));
  25. /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $record2 */
  26. $record2 = $this->getMockBuilder(\Migration\ResourceModel\Record::class)
  27. ->disableOriginalConstructor()
  28. ->getMock();
  29. $handler = new ConvertIp();
  30. $handler->setField($fieldName);
  31. $this->assertNull($handler->handle($record, $record2));
  32. }
  33. }