Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataMapperResolverTest.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class DataMapperResolverTest extends \PHPUnit\Framework\TestCase
14 {
18  private $model;
19 
23  private $dataMapperFactoryMock;
24 
28  private $dataMapperEntity;
29 
33  protected function setUp()
34  {
35  $this->dataMapperFactoryMock = $this->getMockBuilder(DataMapperFactory::class)
36  ->disableOriginalConstructor()
37  ->getMock();
38  $this->dataMapperEntity = $this->getMockBuilder(BatchDataMapperInterface::class)
39  ->disableOriginalConstructor()
40  ->getMock();
41  $this->model = (new ObjectManagerHelper($this))->getObject(
42  \Magento\Elasticsearch\Model\Adapter\BatchDataMapper\DataMapperResolver::class,
43  [
44  'dataMapperFactory' => $this->dataMapperFactoryMock
45  ]
46  );
47  }
48 
49  public function testMapWithDefaultEntityType()
50  {
51  $this->dataMapperEntity->expects($this->once())->method('map')->withAnyParameters();
52  $this->dataMapperFactoryMock->expects($this->once())->method('create')
53  ->with('product')
54  ->willReturn($this->dataMapperEntity);
55 
56  $this->model->map(['data'], 1, []);
57  }
58 
60  {
61  $this->dataMapperEntity->expects($this->once())->method('map')->withAnyParameters();
62  $this->dataMapperFactoryMock->expects($this->once())->method('create')
63  ->with('specific-type')
64  ->willReturn($this->dataMapperEntity);
65 
66  $this->model->map(['data'], 1, ['entityType' => 'specific-type']);
67  }
68 }