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