DataMapperResolverTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Elasticsearch\Test\Unit\Model\Adapter\BatchDataMapper;
  7. use Magento\Elasticsearch\Model\Adapter\BatchDataMapper\DataMapperFactory;
  8. use Magento\Elasticsearch\Model\Adapter\BatchDataMapperInterface;
  9. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  10. use Magento\Elasticsearch\Model\Adapter\BatchDataMapper\DataMapperResolver;
  11. class DataMapperResolverTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var DataMapperResolver
  15. */
  16. private $model;
  17. /**
  18. * @var DataMapperFactory|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $dataMapperFactoryMock;
  21. /**
  22. * @var BatchDataMapperInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $dataMapperEntity;
  25. /**
  26. * @return void
  27. */
  28. protected function setUp()
  29. {
  30. $this->dataMapperFactoryMock = $this->getMockBuilder(DataMapperFactory::class)
  31. ->disableOriginalConstructor()
  32. ->getMock();
  33. $this->dataMapperEntity = $this->getMockBuilder(BatchDataMapperInterface::class)
  34. ->disableOriginalConstructor()
  35. ->getMock();
  36. $this->model = (new ObjectManagerHelper($this))->getObject(
  37. \Magento\Elasticsearch\Model\Adapter\BatchDataMapper\DataMapperResolver::class,
  38. [
  39. 'dataMapperFactory' => $this->dataMapperFactoryMock
  40. ]
  41. );
  42. }
  43. public function testMapWithDefaultEntityType()
  44. {
  45. $this->dataMapperEntity->expects($this->once())->method('map')->withAnyParameters();
  46. $this->dataMapperFactoryMock->expects($this->once())->method('create')
  47. ->with('product')
  48. ->willReturn($this->dataMapperEntity);
  49. $this->model->map(['data'], 1, []);
  50. }
  51. public function testMapWithSpecifiedEntityType()
  52. {
  53. $this->dataMapperEntity->expects($this->once())->method('map')->withAnyParameters();
  54. $this->dataMapperFactoryMock->expects($this->once())->method('create')
  55. ->with('specific-type')
  56. ->willReturn($this->dataMapperEntity);
  57. $this->model->map(['data'], 1, ['entityType' => 'specific-type']);
  58. }
  59. }