123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Elasticsearch\Test\Unit\Model\Adapter\FieldMapper;
- use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
- use Magento\Elasticsearch\Model\Adapter\FieldMapper\FieldMapperResolver;
- use Magento\Framework\ObjectManagerInterface;
- class FieldMapperResolverTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var FieldMapperResolver
- */
- private $model;
- /**
- * @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $objectManagerMock;
- /**
- * @var string[]
- */
- private $fieldMappers;
- /**
- * @var FieldMapperInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $fieldMapperEntity;
- /**
- * Set up test environment
- *
- * @return void
- */
- protected function setUp()
- {
- $this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->fieldMapperEntity = $this->getMockBuilder(
- \Magento\Elasticsearch\Model\Adapter\FieldMapperInterface::class
- )
- ->disableOriginalConstructor()
- ->getMock();
- $this->fieldMappers = [
- 'product' => 'productFieldMapper',
- ];
- $objectManager = new ObjectManagerHelper($this);
- $this->model = $objectManager->getObject(
- \Magento\Elasticsearch\Model\Adapter\FieldMapper\FieldMapperResolver::class,
- [
- 'objectManager' => $this->objectManagerMock,
- 'fieldMappers' => $this->fieldMappers
- ]
- );
- }
- /**
- * Test getFieldName() with Exception
- * @return void
- * @expectedException \Exception
- */
- public function testGetFieldNameEmpty()
- {
- $this->model->getFieldName('attribute', ['entityType' => '']);
- }
- /**
- * Test getFieldName() with Exception
- * @return void
- * @expectedException \LogicException
- */
- public function testGetFieldNameWrongType()
- {
- $this->model->getFieldName('attribute', ['entityType' => 'error']);
- }
- /**
- * Test getFieldName() with Exception
- * @return void
- * @expectedException \InvalidArgumentException
- */
- public function testGetFieldNameFailure()
- {
- $this->objectManagerMock->expects($this->once())
- ->method('create')
- ->willReturn(false);
- $this->model->getFieldName('attribute', ['entityType' => 'product']);
- }
- /**
- * Test getFieldName() method
- * @return void
- */
- public function testGetFieldName()
- {
- $this->objectManagerMock->expects($this->once())
- ->method('create')
- ->willReturn($this->fieldMapperEntity);
- $this->model->getFieldName('attribute', []);
- }
- /**
- * Test getAllAttributesTypes() method
- * @return void
- */
- public function testGetAllAttributesTypes()
- {
- $this->objectManagerMock->expects($this->once())
- ->method('create')
- ->willReturn($this->fieldMapperEntity);
- $this->model->getAllAttributesTypes([]);
- }
- }
|