Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FieldMapperResolverTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class FieldMapperResolverTest extends \PHPUnit\Framework\TestCase
13 {
17  private $model;
18 
22  private $objectManagerMock;
23 
27  private $fieldMappers;
28 
32  private $fieldMapperEntity;
33 
39  protected function setUp()
40  {
41  $this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
42  ->disableOriginalConstructor()
43  ->getMock();
44  $this->fieldMapperEntity = $this->getMockBuilder(
45  \Magento\Elasticsearch\Model\Adapter\FieldMapperInterface::class
46  )
47  ->disableOriginalConstructor()
48  ->getMock();
49  $this->fieldMappers = [
50  'product' => 'productFieldMapper',
51  ];
52  $objectManager = new ObjectManagerHelper($this);
53  $this->model = $objectManager->getObject(
54  \Magento\Elasticsearch\Model\Adapter\FieldMapper\FieldMapperResolver::class,
55  [
56  'objectManager' => $this->objectManagerMock,
57  'fieldMappers' => $this->fieldMappers
58  ]
59  );
60  }
61 
67  public function testGetFieldNameEmpty()
68  {
69  $this->model->getFieldName('attribute', ['entityType' => '']);
70  }
71 
77  public function testGetFieldNameWrongType()
78  {
79  $this->model->getFieldName('attribute', ['entityType' => 'error']);
80  }
81 
87  public function testGetFieldNameFailure()
88  {
89  $this->objectManagerMock->expects($this->once())
90  ->method('create')
91  ->willReturn(false);
92  $this->model->getFieldName('attribute', ['entityType' => 'product']);
93  }
94 
99  public function testGetFieldName()
100  {
101  $this->objectManagerMock->expects($this->once())
102  ->method('create')
103  ->willReturn($this->fieldMapperEntity);
104  $this->model->getFieldName('attribute', []);
105  }
106 
111  public function testGetAllAttributesTypes()
112  {
113  $this->objectManagerMock->expects($this->once())
114  ->method('create')
115  ->willReturn($this->fieldMapperEntity);
116  $this->model->getAllAttributesTypes([]);
117  }
118 }
$objectManager
Definition: bootstrap.php:17