Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeTypeResolverTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\Reflection\AttributeTypeResolver;
10 
11 class AttributeTypeResolverTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $model;
17 
21  protected $typeProcessor;
22 
26  protected $configMock;
27 
31  protected function setUp()
32  {
33  $this->typeProcessor = $this->createMock(\Magento\Framework\Reflection\TypeProcessor::class);
34  $this->configMock = $this->createMock(\Magento\Framework\Api\ExtensionAttribute\Config::class);
35  $this->model = new AttributeTypeResolver($this->typeProcessor, $this->configMock);
36  }
37 
43  {
44  $code = 'some_code';
45  $value = 'string';
46  $context = 'Some\Class';
47  $this->model->resolveObjectType($code, $value, $context);
48  }
49 
51  {
52  $code = 'some_code';
53  $value = new \stdClass();
54  $context = 'Some\Class';
55 
56  $this->configMock->expects($this->once())->method('get')->willReturn([]);
57  $this->assertEquals('stdClass', $this->model->resolveObjectType($code, $value, $context));
58  }
59 
61  {
62  $code = 'some_code';
63  $value = new \stdClass();
64  $context = '\Some\Class';
65  $config = [
66  'Some\Class' => [
67  'some_code' => [
68  'type' => \Magento\Framework\DataObject::class,
69  ],
70  ]
71  ];
72 
73  $this->typeProcessor->expects($this->once())
74  ->method('getArrayItemType')
75  ->with(\Magento\Framework\DataObject::class)
76  ->willReturn(\Magento\Framework\DataObject::class);
77 
78  $this->configMock->expects($this->once())->method('get')->willReturn($config);
79  $this->assertEquals(
80  \Magento\Framework\DataObject::class,
81  $this->model->resolveObjectType($code, $value, $context)
82  );
83  }
84 
89  {
90  $code = 'some_code';
91  $value = new \stdClass();
92  $context = '\Some\Class';
93  $config = [
94  'Some\Class' => [
95  'some_code' => [
96  'type' => '\Some\Class',
97  ]
98  ]
99  ];
100 
101  $this->typeProcessor->expects($this->once())
102  ->method('getArrayItemType')
103  ->with('\Some\Class')
104  ->willReturn('\Some\Class');
105 
106  $this->configMock->expects($this->once())->method('get')->willReturn($config);
107  $this->model->resolveObjectType($code, $value, $context);
108 
109  $this->expectExceptionMessage(
110  'The "\Some\Class" class doesn\'t exist and the namespace must be specified. Verify and try again.'
111  );
112  }
113 }
$config
Definition: fraud_order.php:17
$value
Definition: gender.phtml:16
$code
Definition: info.phtml:12