Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeResolverTest.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class AttributeResolverTest extends \PHPUnit\Framework\TestCase
14 {
16  protected $model;
17 
20 
21  protected function setUp()
22  {
23  $this->metadataDataProviderMock = $this->getMockBuilder(
24  \Magento\Customer\Model\AttributeMetadataDataProvider::class
25  )->disableOriginalConstructor()->getMock();
26 
27  $this->model = new AttributeResolver(
28  $this->metadataDataProviderMock
29  );
30  }
31 
32  public function testGetModelByAttribute()
33  {
34  $entityType = 'type';
35  $attributeCode = 'code';
36 
38  $attributeMock = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
39  ->disableOriginalConstructor()
40  ->getMock();
41  $attributeMock->expects($this->once())
42  ->method('getAttributeCode')
43  ->willReturn($attributeCode);
44 
46  $modelMock = $this->getMockBuilder(\Magento\Customer\Model\Attribute::class)
47  ->disableOriginalConstructor()
48  ->getMock();
49 
50  $this->metadataDataProviderMock->expects($this->once())
51  ->method('getAttribute')
53  ->willReturn($modelMock);
54 
55  $this->assertEquals($modelMock, $this->model->getModelByAttribute($entityType, $attributeMock));
56  }
57 
62  public function testGetModelByAttributeWithoutModel()
63  {
64  $entityType = 'type';
65  $attributeCode = 'code';
66 
68  $attributeMock = $this->getMockBuilder(\Magento\Customer\Api\Data\AttributeMetadataInterface::class)
69  ->disableOriginalConstructor()
70  ->getMock();
71  $attributeMock->expects($this->exactly(2))
72  ->method('getAttributeCode')
73  ->willReturn($attributeCode);
74 
75  $this->metadataDataProviderMock->expects($this->once())
76  ->method('getAttribute')
78  ->willReturn(false);
79 
80  $this->model->getModelByAttribute($entityType, $attributeMock);
81  }
82 }
$attributeCode
Definition: extend.phtml:12