Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ArgumentsResolverTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class ArgumentsResolverTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $model;
17 
21  protected $diContainerConfig;
22 
23  protected function setUp()
24  {
25  $this->diContainerConfig = $this->createMock(\Magento\Framework\ObjectManager\ConfigInterface::class);
26  $this->model = new \Magento\Setup\Module\Di\Compiler\ArgumentsResolver($this->diContainerConfig);
27  }
28 
30  {
31  $expectedResultDefault = $this->getResolvedSimpleConfigExpectation();
32 
33  $constructor = [
34  new ConstructorArgument(['type_dependency', 'Type\Dependency', true, null]),
35  new ConstructorArgument(['type_dependency_shared', 'Type\Dependency\Shared', true, null]),
36  new ConstructorArgument(['value', null, false, 'value']),
37  new ConstructorArgument(['value_array', null, false, ['default_value1', 'default_value2']]),
38  new ConstructorArgument(['value_null', null, false, null]),
39  ];
40  $this->diContainerConfig->expects($this->any())
41  ->method('isShared')
42  ->willReturnMap(
43  [
44  ['Type\Dependency', false],
45  ['Type\Dependency\Shared', true]
46  ]
47  );
48 
49  $type = 'Class';
50  $this->diContainerConfig->expects($this->any())
51  ->method('getArguments')
52  ->with($type)
53  ->willReturn([]);
54 
55  $this->assertSame(
56  $expectedResultDefault,
57  $this->model->getResolvedConstructorArguments($type, $constructor)
58  );
59  }
60 
62  {
63  $expectedResultConfigured = $this->getResolvedConfigurableConfigExpectation();
64 
65  $constructor = [
66  new ConstructorArgument(['type_dependency_configured', 'Type\Dependency', true, null]),
67  new ConstructorArgument(['type_dependency_shared_configured', 'Type\Dependency\Shared', true, null]),
68  new ConstructorArgument(['global_argument', null, false, null]),
69  new ConstructorArgument(['global_argument_def', null, false, []]),
70  new ConstructorArgument(['value_configured', null, false, 'value']),
71  new ConstructorArgument(['value_array_configured', null, false, []]),
72  new ConstructorArgument(['value_null', null, false, null]),
73  ];
74 
75  $this->diContainerConfig->expects($this->any())
76  ->method('isShared')
77  ->willReturnMap(
78  [
79  ['Type\Dependency', false],
80  ['Type\Dependency\Shared', true],
81  ['Type\Dependency\Configured', false],
82  ['Type\Dependency\Shared\Configured', true]
83  ]
84  );
85 
86  $type = 'Class';
87  $this->diContainerConfig->expects($this->any())
88  ->method('getArguments')
89  ->with($type)
90  ->willReturn(
91  $this->getConfiguredArguments()
92  );
93 
94  $this->assertSame(
95  $expectedResultConfigured,
96  $this->model->getResolvedConstructorArguments($type, $constructor)
97  );
98  }
99 
105  private function getResolvedSimpleConfigExpectation()
106  {
107  return [
108  'type_dependency' => [
109  '_ins_' => 'Type\Dependency',
110  ],
111  'type_dependency_shared' => [
112  '_i_' => 'Type\Dependency\Shared',
113  ],
114  'value' => [
115  '_v_' => 'value',
116  ],
117  'value_array' => [
118  '_v_' => ['default_value1', 'default_value2'],
119  ],
120  'value_null' => [
121  '_vn_' => true,
122  ],
123  ];
124  }
125 
131  private function getConfiguredArguments()
132  {
133  return [
134  'type_dependency_configured' => ['instance' => 'Type\Dependency\Configured'],
135  'type_dependency_shared_configured' => ['instance' => 'Type\Dependency\Shared\Configured'],
136  'global_argument' => ['argument' => 'global_argument_configured'],
137  'global_argument_def' => ['argument' => 'global_argument_configured'],
138  'value_configured' => 'value_configured',
139  'value_array_configured' => [
140  'array_value' => 'value',
141  'array_configured_instance' => ['instance' => 'Type\Dependency\Shared\Configured'],
142  'array_configured_array' => [
143  'array_array_value' => 'value',
144  'array_array_configured_instance' => [
145  'instance' => 'Type\Dependency\Shared\Configured',
146  'shared' => false
147  ]
148  ],
149  'array_global_argument' => ['argument' => 'global_argument_configured']
150  ],
151  'value_null' => null,
152  ];
153  }
154 
160  private function getResolvedConfigurableConfigExpectation()
161  {
162  return [
163  'type_dependency_configured' => [
164  '_ins_' => 'Type\Dependency\Configured',
165  ],
166  'type_dependency_shared_configured' => [
167  '_i_' => 'Type\Dependency\Shared\Configured',
168  ],
169  'global_argument' => [
170  '_a_' => 'global_argument_configured',
171  '_d_' => null
172  ],
173  'global_argument_def' => [
174  '_a_' => 'global_argument_configured',
175  '_d_' => []
176  ],
177  'value_configured' => [
178  '_v_' => 'value_configured',
179  ],
180  'value_array_configured' => [
181  '_vac_' => [
182  'array_value' => 'value',
183  'array_configured_instance' => [
184  '_i_' => 'Type\Dependency\Shared\Configured',
185  ],
186  'array_configured_array' => [
187  'array_array_value' => 'value',
188  'array_array_configured_instance' => [
189  '_ins_' => 'Type\Dependency\Shared\Configured',
190  ],
191  ],
192  'array_global_argument' => [
193  '_a_' => 'global_argument_configured',
194  '_d_' => null
195  ]
196  ],
197  ],
198  'value_null' => [
199  '_vn_' => true,
200  ],
201  ];
202  }
203 }
return false
Definition: gallery.phtml:36
$type
Definition: item.phtml:13