12
12
use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable \Attribute ;
13
13
use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
14
14
use Magento \Eav \Model \Entity \Attribute \Source \AbstractSource ;
15
- use Magento \Framework \App \ScopeInterface ;
16
- use Magento \Framework \App \ScopeResolverInterface ;
17
15
use Magento \Framework \DB \Adapter \AdapterInterface ;
18
16
use Magento \Framework \DB \Select ;
19
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
20
17
use PHPUnit \Framework \MockObject \MockObject ;
21
18
use PHPUnit \Framework \TestCase ;
22
19
@@ -30,16 +27,6 @@ class AttributeOptionProviderTest extends TestCase
30
27
*/
31
28
private $ model ;
32
29
33
- /**
34
- * @var ObjectManagerHelper
35
- */
36
- private $ objectManagerHelper ;
37
-
38
- /**
39
- * @var ScopeResolverInterface|MockObject
40
- */
41
- private $ scopeResolver ;
42
-
43
30
/**
44
31
* @var Select|MockObject
45
32
*/
@@ -55,11 +42,6 @@ class AttributeOptionProviderTest extends TestCase
55
42
*/
56
43
private $ abstractAttribute ;
57
44
58
- /**
59
- * @var ScopeInterface|MockObject
60
- */
61
- private $ scope ;
62
-
63
45
/**
64
46
* @var Attribute|MockObject
65
47
*/
@@ -72,45 +54,13 @@ class AttributeOptionProviderTest extends TestCase
72
54
73
55
protected function setUp (): void
74
56
{
75
- $ this ->select = $ this ->getMockBuilder (Select::class)
76
- ->setMethods ([])
77
- ->disableOriginalConstructor ()
78
- ->getMock ();
79
-
80
- $ this ->connectionMock = $ this ->getMockBuilder (AdapterInterface::class)
81
- ->disableOriginalConstructor ()
82
- ->getMockForAbstractClass ();
57
+ $ this ->select = $ this ->createMock (Select::class);
58
+ $ this ->connectionMock = $ this ->createMock (AdapterInterface::class);
59
+ $ this ->attributeResource = $ this ->createMock (Attribute::class);
60
+ $ this ->optionSelectBuilder = $ this ->createMock (OptionSelectBuilderInterface::class);
61
+ $ this ->abstractAttribute = $ this ->createMock (AbstractAttribute::class);
83
62
84
- $ this ->scope = $ this ->getMockBuilder (ScopeInterface::class)
85
- ->disableOriginalConstructor ()
86
- ->getMockForAbstractClass ();
87
-
88
- $ this ->scopeResolver = $ this ->getMockBuilder (ScopeResolverInterface::class)
89
- ->disableOriginalConstructor ()
90
- ->getMockForAbstractClass ();
91
-
92
- $ this ->attributeResource = $ this ->getMockBuilder (Attribute::class)
93
- ->disableOriginalConstructor ()
94
- ->getMock ();
95
-
96
- $ this ->optionSelectBuilder = $ this ->getMockBuilder (OptionSelectBuilderInterface::class)
97
- ->disableOriginalConstructor ()
98
- ->getMockForAbstractClass ();
99
-
100
- $ this ->abstractAttribute = $ this ->getMockBuilder (AbstractAttribute::class)
101
- ->setMethods (['getSourceModel ' , 'getSource ' ])
102
- ->disableOriginalConstructor ()
103
- ->getMockForAbstractClass ();
104
-
105
- $ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
106
- $ this ->model = $ this ->objectManagerHelper ->getObject (
107
- AttributeOptionProvider::class,
108
- [
109
- 'attributeResource ' => $ this ->attributeResource ,
110
- 'scopeResolver ' => $ this ->scopeResolver ,
111
- 'optionSelectBuilder ' => $ this ->optionSelectBuilder ,
112
- ]
113
- );
63
+ $ this ->model = new AttributeOptionProvider ($ this ->attributeResource , $ this ->optionSelectBuilder );
114
64
}
115
65
116
66
/**
@@ -119,13 +69,9 @@ protected function setUp(): void
119
69
*/
120
70
public function testGetAttributeOptions (array $ options )
121
71
{
122
- $ this ->scopeResolver ->expects ($ this ->any ())
123
- ->method ('getScope ' )
124
- ->willReturn ($ this ->scope );
125
-
126
- $ this ->optionSelectBuilder ->expects ($ this ->any ())
72
+ $ this ->optionSelectBuilder ->expects ($ this ->once ())
127
73
->method ('getSelect ' )
128
- ->with ($ this ->abstractAttribute , 4 , $ this -> scope )
74
+ ->with ($ this ->abstractAttribute , 4 )
129
75
->willReturn ($ this ->select );
130
76
131
77
$ this ->attributeResource ->expects ($ this ->once ())
@@ -149,14 +95,7 @@ public function testGetAttributeOptions(array $options)
149
95
*/
150
96
public function testGetAttributeOptionsWithBackendModel (array $ options )
151
97
{
152
- $ this ->scopeResolver ->expects ($ this ->any ())
153
- ->method ('getScope ' )
154
- ->willReturn ($ this ->scope );
155
-
156
- $ source = $ this ->getMockBuilder (AbstractSource::class)
157
- ->disableOriginalConstructor ()
158
- ->setMethods (['getAllOptions ' ])
159
- ->getMockForAbstractClass ();
98
+ $ source = $ this ->createMock (AbstractSource::class);
160
99
$ source ->expects ($ this ->once ())
161
100
->method ('getAllOptions ' )
162
101
->willReturn ([
@@ -165,16 +104,16 @@ public function testGetAttributeOptionsWithBackendModel(array $options)
165
104
['value ' => 15 , 'label ' => 'Option Value for index 15 ' ]
166
105
]);
167
106
168
- $ this ->abstractAttribute ->expects ($ this ->any ())
107
+ $ this ->abstractAttribute ->expects ($ this ->atLeastOnce ())
169
108
->method ('getSource ' )
170
109
->willReturn ($ source );
171
110
$ this ->abstractAttribute ->expects ($ this ->atLeastOnce ())
172
111
->method ('getSourceModel ' )
173
112
->willReturn ('getSourceModel value ' );
174
113
175
- $ this ->optionSelectBuilder ->expects ($ this ->any ())
114
+ $ this ->optionSelectBuilder ->expects ($ this ->once ())
176
115
->method ('getSelect ' )
177
- ->with ($ this ->abstractAttribute , 1 , $ this -> scope )
116
+ ->with ($ this ->abstractAttribute , 1 )
178
117
->willReturn ($ this ->select );
179
118
180
119
$ this ->attributeResource ->expects ($ this ->once ())
0 commit comments